I’m trying to get the max product of 4 adjacent numbers in an array
this is what I got now:
let max4 line =
let rec loop acc = function
|a :: b :: c :: [] -> acc
|a :: b :: c :: d :: tl -> loop (max(acc, a*b*c*d)) tl
|_ -> 0
loop 0 line
I get a compilation error on the max(,) saying:
error FS0001: Type mismatch. Expecting a
‘a but given a
‘a * ‘b -> ‘a * ‘b The resulting type would be infinite when unifying ”a’ and ”a * ‘b -> ‘a * ‘b’
Anybody knows what’s wrong in this code ? (or another solution)
Suppose the input is a list of integers:
You made some mistakes:
maxfunction is in the curry formmax: 'a -> 'a -> 'a.b::c::d::tl, nottlonly.0is not a good starting point. Beware that integer overflow could happen (which I still haven’t addressed in my function).