具备以下职能:
let rec transpose = function
| (_::_)::_ as M -> List.map List.head M :: transpose (List.map List.tail M)
| _ -> []
[[1; 2; 3]; [4; 5; 6]; [7; 8; 9]] |> transpose |> printfn "%A"
It works fine.
What does ( _ :: _ ) :: _ mean?
I don t understand the whole code!
Who can explain it?
Thank You!
I find the answer:
( _ :: _ ) :: _ is a pattern matching on value of type list of lists of ints
www.un.org/Depts/DGACM/index_spanish.htm i 书写:
let rec transpose (M:int list list) =
match M with
| hd::tl -> List.map List.head M :: transpose (List.map List.tail M)
| _ -> []
It throw an runtime exception. Is there something wrong with hd?
Yes, it make something like [ [ ];[ ];[ ] ] when call List.tail, then it throws exception when call List.head!
Problem Solved!
Thank you all!