algorithm - adding a number to a list within a function OCaml -
here have , error getting sadly
error: function has type 'a * 'a list -> 'a list applied many arguments; maybe forgot `;'.
why case? plan on passing 2 lists deleteduplicates function, sorted list, , empty list, , expect duplicates removed in list r, returned once original list reaches []
condition.
will updated code
let myfunc_caml_way arg0 arg1 = ... rather let myfunc_java_way(arg0, arg1) = ... can call function in way: myfunc_caml_way "10" 123 rather myfunc_java_way("10, 123)
i don't know how useful might be, here code want, written in standard ocaml style. spend time making sure understand how , why works. maybe should start simpler (eg how sum elements of list of integers ?). actually, should start ocaml tutorial, reading , making sure aunderstand code examples.
let deleteduplicates u = (* u : sorted list v : result far last : last element read u *) let rec aux u v last = match u [] -> v | x::xs when x = last -> aux xs v last | x::xs -> aux u (x::v) x in (* first element special case *) match u [] -> [] | x::xs -> list.rev (aux xs [x] x)
Comments
Post a Comment