Reputation: 3906
I currently am attempting this.
let L = [2; 4; 6; 8]
let fourth listx = List.nth(listx 3);;
fourth L;;
but I want 'a -> 'a
(list to list) not int -> 'a
How do I fix this?
Upvotes: 0
Views: 143
Reputation: 567
let fourth x = (fun x -> [x]) (List.nth x 3)
val fourth : x:'a list -> 'a list
Upvotes: 0
Reputation: 25516
You want something like
let fourth listx = List.nth listx 3
This gives a signature of 'a list -> 'a
which is I think what you want. The key difference is the absence of brackets which don't do what you are expecting in this case
Upvotes: 4