Saturday, February 8, 2014

Ocaml Note On Syntax

Try not to omit parentheses and commas, especially for the function parameters and in the function calls...

This worked...
 let rec assoc (value, key, list)= match list with
 |[] -> value
 | (key', value')::tail -> if key = key' then value' else assoc(value, key, tail);;

But this didn't...
let rec assoc value key list = match list with
 |[] -> value
 | (key', value')::tail -> if key = key' then value' else assoc value key tail;;

Edit: I've found that this was the case for every recursive function with more than 1 parameter. Still unsure as to why...

No comments:

Post a Comment