Value restriction in F# -
i've got f# assignment trying compute transpose of matrix. simple enough, maintain getting value restriction error , cannot figure out why. consulted many of vr error questions out there, i'm still in dark. here's code:
let transpose = function | [xs ; ys] -> allow rec transpose_helper = function | [],[] -> [] | x::xs , y::ys -> [x;y] :: transpose_helper (xs,ys) | _ -> failwith "the matrix not square matrix" transpose_helper(xs,ys) | _ -> failwith "incorrectly formatted input" transpose ([[1;2;3];[2;3;4]]);;
i assume error in part due empty list, nil seems help. pointers appreciated.
edit: next version of code, works. explain why?
let transpose zs = match zs | [xs;ys] -> allow rec transpose_helper (xs, ys) = match (xs,ys) | ([],[]) -> [] | (x::xs , y::ys) -> [x;y] :: transpose_helper (xs,ys) | _ -> failwith "the matrix not square matrix" transpose_helper(xs,ys) | _ -> failwith "incorrectly formatted input" transpose ([[1;2;3];[2;3;4]]);; val transpose : zs:'a list list -> 'a list list val : int list list = [[1; 2]; [2; 3]; [3; 4]]
however, compiler still complains transpose phone call above should have unit type unless bind using lets. please clarify going on here?
my guess wrote let rec transpose zs = match zs ...
, later changed utilize function
instead, removes need explicit argument. since zs
still there function accepts 2 args means you're partially applying it. since zs
unused type unknown making partially applied function homecoming generic function value (value restriction). remove zs
, well.
f# value-restriction
No comments:
Post a Comment