Last active
April 3, 2017 20:22
-
-
Save xaviervia/f00af28ecdeb4c1ebb4ba0e984a51ad2 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
import Data.Vect | |
Matrix : Nat -> Nat -> Type -> Type | |
Matrix x y t = Vect x (Vect y t) | |
createEmpties : Vect n (Vect 0 elem) | |
createEmpties = replicate _ [] | |
transposeMatrix : Matrix rows columns elem -> | |
Matrix columns rows elem | |
transposeMatrix [] = createEmpties | |
transposeMatrix (row :: rows) = | |
let | |
transposedRows = transposeMatrix rows | |
in | |
zipWith (::) row transposedRows | |
multiplyMatrix : Num numType => | |
Matrix firstRows n numType -> | |
Matrix n secondColumns numType -> | |
Matrix firstRows secondColumns numType | |
multiplyMatrix [] [] = [] -- for empty element we do nothing | |
multiplyMatrix [] (secondRow :: secondRows) = [] | |
multiplyMatrix (firstRow :: firstRows) [] = ?onlyFirstMatrix | |
multiplyMatrix (firstRow :: firstRows) secondMatrix = | |
let | |
transposedSecondMatrix = transposeMatrix secondMatrix | |
(transposedSecondRow :: transposedSecondRows) = transposedSecondMatrix | |
in | |
multiplyHelper transposedSecondRow firstRow firstRows transposedSecondRows transposedSecondMatrix secondMatrix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment