I have checked everywhere and I can’t seem to locate the problem. The compiler is giving me this error: “error FS0039: The value or constructor 'dotProduct' is not defined“. But dotProduct is currently defined.
Visual Studio 2010 is also highlighting the second let (let rec dotProductAux list1 list2 acum =) saying that the expression is unfinished.
let dotProduct list1 list2 =
let rec dotProductAux list1 list2 acum =
match list1 ,list2 with
| [],l | l,[] -> acum
| head1 :: tail1, head2 :: tail2 -> let updated = (head1 * head2) + acum
(dotProductAux tail1 tail2 updated)
This code multiplies and adds two list like this:
dotProduct [1;4;7] [3;4;1];; //(1*3) + (4*4) + (7*1)
I’m fairly new to F# and can’t seem to get this code right. Any help?
The body of
dotProductcontains the definition ofdotProductAux, but no actual expression. You need to actually calldotProductAux(i.e. you’re missing the calldotProductAux list1 list2 0after thelet rec).Furthermore the case(Apparently you’ve already fixed this in an edit).| [],[]| l,[] -> accumwill cause an error because the second pattern binds the variablel, while the first does not. You can fix that by replacinglwith_, since you don’t actually need it.