mirror of
https://github.com/Noratrieb/idris-learning.git
synced 2026-01-14 21:15:02 +01:00
chapter 3 finished
This commit is contained in:
parent
c43a16ecde
commit
9c41b5059e
2 changed files with 39 additions and 0 deletions
30
chapter3/Matrix.idr
Normal file
30
chapter3/Matrix.idr
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
module Matrix
|
||||
|
||||
import Data.Vect
|
||||
|
||||
addMatrix : Num numType =>
|
||||
Vect rows (Vect cols numType) ->
|
||||
Vect rows (Vect cols numType) ->
|
||||
Vect rows (Vect cols numType)
|
||||
addMatrix = zipWith (zipWith (+))
|
||||
|
||||
multMatrix : Num numType =>
|
||||
Vect n (Vect m numType) -> Vect m (Vect p numType) ->
|
||||
Vect n (Vect p numType)
|
||||
-- 😔
|
||||
|
||||
createEmpties : Vect n (Vect 0 elem)
|
||||
createEmpties = replicate _ []
|
||||
|
||||
createEmpties2 : Vect n (Vect 0 elem)
|
||||
createEmpties2 {n = Z} = []
|
||||
createEmpties2 {n = (S k)} = [] :: createEmpties2
|
||||
|
||||
|
||||
transHelper : (x : Vect n elem) -> (xsTrans : Vect n (Vect len elem)) -> Vect n (Vect (S len) elem)
|
||||
transHelper = zipWith (\x, y => x :: y)
|
||||
|
||||
transposeMat : Vect m (Vect n elem) -> Vect n (Vect m elem)
|
||||
transposeMat [] = createEmpties
|
||||
transposeMat (x :: xs) = let xsTrans = transposeMat xs in
|
||||
transHelper x xsTrans
|
||||
|
|
@ -52,3 +52,12 @@ my_map f (x :: xs) = (f x) :: my_map f xs
|
|||
my_vect_map : (a -> b) -> Vect n a -> Vect n b
|
||||
my_vect_map _ [] = []
|
||||
my_vect_map f (x :: xs) = (f x) :: my_vect_map f xs
|
||||
|
||||
|
||||
lengthLong : Vect n elem -> Nat
|
||||
lengthLong [] = 0
|
||||
lengthLong (x :: xs) = S (lengthLong xs)
|
||||
|
||||
|
||||
lengthLong2 : Vect n elem -> Nat
|
||||
lengthLong2 {n} xs = n
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue