Name: Anonymous 2015-03-28 10:42
I'm reading Coq in a Hurry.
https://cel.archives-ouvertes.fr/file/index/docid/459139/filename/coq-hurry.pdf
On page 8 there is the following exercise
I have written the following code.
This produces the list in reverse order (nevermind it is [1..n], not [0..n-1]). Is there any functional way to produce a list in increasing order without using reverse? Keep in mind this is page 8 and I think I am not supposed to use auxiliary functions (or maybe I am?).
https://cel.archives-ouvertes.fr/file/index/docid/459139/filename/coq-hurry.pdf
On page 8 there is the following exercise
Exercise on lists, map, and app. (app is like ++ in Haskell)
Define a function that takes as input a number n and returns a list with n elements, from 0 to n − 1.
I have written the following code.
Fixpoint ex2 (n : nat) :=
match n with
0 => (nil : list nat)
| S p => n :: ex2 p
end.
This produces the list in reverse order (nevermind it is [1..n], not [0..n-1]). Is there any functional way to produce a list in increasing order without using reverse? Keep in mind this is page 8 and I think I am not supposed to use auxiliary functions (or maybe I am?).