Beginner question about lambdas #2879
Answered
by
TheoWinterhalter
chandradeepdey
asked this question in
Q&A
-
I was playing around with the examples in the tutorials and could not make sense of this error. Why do let rec append (#a: Type) (l1 l2: list a) : (l: list a {length l = length l1 + length l2}) =
match l1 with
| [] -> l2
| hd :: tl -> hd :: append tl l2 and let rec append (#a: Type) (l1 l2: list a) : (l: list a {length l = length l1 + length l2}) =
(fun (l2': list a) ->
(match l1 with
| [] -> l2'
| hd :: tl -> hd :: append tl l2')) l2 work but let rec append (#a: Type) (l1 l2: list a) : (l: list a {length l = length l1 + length l2}) =
(fun (l1': list a) ->
l2': list a
-> (match l1' with
| [] -> l2'
| hd :: tl -> hd :: append tl l2')) l1
l2 fail with
? Why should it be |
Beta Was this translation helpful? Give feedback.
Answered by
TheoWinterhalter
Apr 8, 2023
Replies: 1 comment 1 reply
-
In your last example you have |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
chandradeepdey
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In your last example you have
l2': list a -> ...
instead offun (l2' : list a) -> …
so you are indeed writing a function type instead of a function. If you want to writefun
only once, then you should writefun (l1' : list a) (l2' : list a) -> …
.