OCaml - Reverse a list -


i'm trying implement own list module follows :

type 'a my_list =     | item of ('a * 'a my_list)     | empty 

i've implemented several functions , trying create list reversing function module :

let rec rev = function     | empty             -> (*return reversed list*)     | item(i, remnant)  -> (*recursive call rev*) 

moreover, i'm not supposed use list operators such '::', '[]' , '@'.

edit, tried :

let rec rev_append l1 l2 = match l1     | empty             -> l2     | item(i, remnant)  -> rev_append remnant item(i, l2)  let rev l = rev_append l empty;; 

but not working, there error @ second argument passed recursive call : "item(i, l2)" error "the constructor item expects 1 argument, here applied 0 arguments".

parenthesis man !

let rec rev_append l1 l2 = match l1     | empty             -> l2     | item(i, remnant)  -> rev_append remnant (item (i, l2)) 

the compiler understood rev_append passed 3 argument namely remnant item , (i, l2).


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -