real basic question here: I'm new to Ocaml and I'm having issues trying to manipulate lists. I've read http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html, and I'm unfortunately still confused....I'm new to functional programming.
If I have, say, the following function:
let stoverfl list1 list2 list3 =
match list1 with
|[]->None
|h::list1 -> (*what I want to do goes in here*)
I want to take a look at the first elements of list2 and list3, compare them, and if they're equal, add the first element of list3 to list2, else don't modify the lists. I don't really care about error checking now (i.e. checking to see if the list has at least one element, etc.).
My attempt:
h::list1 -> let cmp1 = hd list2 (*this should return the first elemnt of list2??*)
let cmp2 = hd list3
if(cmp1=cmp2) then
let updlist2 = concat list2 hd list3
let updlist3 = hd list3
(*pass updlist2 and updlist3 instead of list2 and list3 to next function*)
else
(*do nothing; pass list2 and list3 as normal*)
I feel like I'm doing it all wrong...any advice would be appreciated! Thanks.