Created
March 9, 2010 19:58
-
-
Save camilopayan/327036 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec inner xs ys = match (xs,ys) with | |
| (x::xs,y::ys) -> (x*y) + inner xs ys | |
| _ -> 0 | |
let rec separate = function | |
| [] -> ([],[]) | |
| []::xs -> ([],[]) | |
| (x::xs)::ys -> let (M,N) = separate ys | |
(x::M, xs::N) | |
let rec transpose = function | |
| [] -> [] | |
| x::xs -> let (q, w) = separate (x::xs) in | |
if List.length(q) = 0 then [] else [q] @ trans w | |
(*Hooray! Slightly more efficient than it was before! Now it'll only transpose that thing once*) | |
let rec multiply = function | |
| ([],ys) -> [] | |
| (x::xs,ys) when (List.length (x)) = (List.length ys) -> | |
multiply(x::xs,transpose ys) | |
| (x::xs,ys) -> List.map (inner x) ys :: multiply(xs,ys) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment