Reputation: 53
I've got an assignment where I have to recode a big part of the different functions found on "list". I'm currently having trouble implementing the rev function.
type 'a my_list =
| Item of ('a * 'a my_list)
| Empty;;
This is the type of lists we are allowed to use and here is my attempt at doing it:
let rev my_list =
let rec rev_list list = function
| Empty -> list
| Item (first, rest) -> rev_list (Item (first, list))
rest in rev_list Empty;;
rev function has for prototype:
'a list -> 'a list:
and this is what I'm getting:
'a -> 'b my_list -> 'b my_list
Any pointers?
Upvotes: 1
Views: 257
Reputation: 53
EDIT: Well, right as I posted the question I found the answer, if it might help anybody, here it is
let rev my_list =
let rec rev_list list = function
| Empty -> list
| Item (first, rest) -> rev_list (Item (first, list))
rest in rev_list Empty my_list
Upvotes: 1