-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvect.idr
36 lines (27 loc) · 1.08 KB
/
vect.idr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
data Vect : Nat -> Type -> Type where
Nil : Vect Z a
(::) : (x : a) -> (xs : Vect k a) -> Vect (S k) a
%name Vect xs, ys, zs
append : Vect n elem -> Vect m elem -> Vect (n + m) elem
append [] ys = ys
append (x :: xs) ys = x :: append xs ys
data VectUnknown : Type -> Type where
MkVect : (len : Nat) -> Vect len a -> VectUnknown a
read_vect : IO (VectUnknown String)
read_vect = do x <- getLine
if (x == "")
then pure (MkVect _ [])
else do MkVect _ xs <- read_vect
pure (MkVect _ (x :: xs))
Show a => Show (Vect n a) where
show [] = ""
show (x :: xs) = show x ++ show xs
printVect : Show a => VectUnknown a -> IO ()
printVect (MkVect len xs) = let xss : String = show xs
lengths : String = show len in
putStrLn (xss ++ " (length " ++ lengths ++ ")")
Eq a => Eq (Vect n a) where
(==) [] [] = True
(==) (x :: xs) (y :: ys) = case x == y of
True => xs == ys
False => False