Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9161575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:59:48+00:00 2026-06-17T13:59:48+00:00

I’m reading through CPDT and there is one example that I’m not understanding: Definition

  • 0

I’m reading through CPDT and there is one example that I’m not understanding:

Definition plus_rec : nat -> nat -> nat :=
  nat_rec (fun _ : nat => nat -> nat) (fun m => m) (fun _ r m => S (r m)).

Most of this makes sense except for the fun _ : nat => nat -> nat. I don’t understand how this can have any meaning at all, this function appears to be returning a type with no value.

Am I misunderstanding something fundamental here about Coq? What is the significance of that lambda?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:59:50+00:00Added an answer on June 17, 2026 at 1:59 pm

    Let’s take a look at nat_rec:

    nat_rec :
      forall P : nat -> Set,
      P O ->
      (forall n : nat, P n -> P (S n)) ->
      forall n : nat, P n
    

    Its first argument is a P which, given a nat, returns a Set. Then you are going to give an element of the set P O, and an element of the set P (S n) assuming you have an element from P n, and finally with all that, you are given back something of type forall n, P n which means it can construct an element of type P n for every n you pass in as input (if you pass O, it’s going to give you back the P O you provided, otherwise it’s going to build your result by repeated applications of the third argument).


    Now, that lambda which is confusing you is that P I’ve been talking about. It is given a nat and from it builds the “return type”. In particular we are trying to have the return type of nat_rec, namely forall n : nat, P n be the type of plus_rec, that is nat -> nat -> nat. This can be done by instantiating P such that for all n, P n = nat -> nat. Which is what we obtain using the lambda-term fun _ : nat => nat -> nat.

    This term ignores the input nat (because nat_rec is general enough to build things whose type depend on the first nat they receive, but the type of plus_rec partially applied to any first argument does not actually depend on the value of that argument). Then it just returns nat -> nat (which is the type of the partial application of addition to one operand: we still expect a nat before we can return the sum nat).


    Now if you take a look at nat_rec partially applied to that funny lambda-term, the type is:

    nat_rec (fun _ : nat => nat -> nat) :
      (fun _ : nat => nat -> nat) O ->
      (forall n : nat, (fun _ : nat => nat -> nat) n -> (fun _ : nat => nat -> nat) (S n)) ->
      forall n : nat, (fun _ : nat => nat -> nat) n
    

    (I just replied P with (fun _ : nat => nat -> nat). Now, this simplifies into:

    nat_rec (fun _ : nat => nat -> nat) :
      (nat -> nat) ->
      (forall n : nat, (nat -> nat) -> (nat -> nat)) ->
      forall n : nat, (nat -> nat)
    

    Now this should definitely be confusing.

    You should think of the first argument you need to give as the type of the partial application of plus to O. It receives the second operand, and returns the sum of the two:

    (fun m => m) (* morally, O + m *)
    

    The second argument is given a (n : nat), a function r : nat -> nat, another m : nat, and needs to return a final nat. It is the most confusing in the bunch. Morally, r is a P n, that is, given our goal, “a function who knows how to add n to its input”. Morally again, the last (nat -> nat) should be a P (S n), that is “a function who knows how to add (S n) to its input”. In particular, we named this input m. You should be able to convince yourself that the result should be:

    (fun _ r m => S (r m))
    (* ignore n, use r (which is the "+ n" function) on m, to get (n + m), and add 1 to get (n + 1) + m *)
    

    With all this, we managed to build the function plus.


    Note that is a very error-prone way to define plus_rec, in particular because you have to remember really hard what is what or you’re not going to define the function you want, because the typing is really loose (see how we ignore the n most of the time). In fact, there was a bug in an earlier draft of that same function, which did type-check.

    I believe this is shown as to show how everything is under the rug, but do not think that this is the way you should define plus_rec in general.


    Finally, this is quite hard to explain and I am pretty sure my answer will not be crystal-clear. Feel free to drop comments and I’ll edit the answer to make things more clean.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
I am reading a book about Javascript and jQuery and using one of the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.