Skip to content

Instantly share code, notes, and snippets.

@chribben
Created August 31, 2012 23:16
Show Gist options
  • Save chribben/3560851 to your computer and use it in GitHub Desktop.
Save chribben/3560851 to your computer and use it in GitHub Desktop.
Matrix multiplication
let mulVectors v1 v2 = List.fold2(fun s x y -> s + x * y) 0 v1 v2
let mulMatr m1 m2 =
let rec mulMatr'' m1 m2 m3 =
let rec mulMatr' m1 m2 v =
match m1, m2 with
| h1::t1, h2::t2 -> mulMatr' t1 m2 ((mulVectors h1 h2)::v)
| [], _ -> List.rev v
| _ -> failwith "error in format"
match m1, m2 with
| h1::t1, h2::t2 -> let v = mulMatr' m1 m2 []
mulMatr'' m1 t2 (v::m3)
| _, [] -> List.rev m3
| _ -> failwith "error in format"
mulMatr'' m1 m2 []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment