Solve homework one and two
This commit is contained in:
commit
399e30f085
24
HomeworkOne.idr
Normal file
24
HomeworkOne.idr
Normal file
|
@ -0,0 +1,24 @@
|
|||
module HomeworkOne
|
||||
import Data.Fin
|
||||
|
||||
%default total
|
||||
|
||||
Tuple : Nat -> Type
|
||||
Tuple Z = Nat
|
||||
Tuple (S n) = (Nat, Tuple n)
|
||||
|
||||
first : { s : Nat } -> Tuple s -> Nat
|
||||
first {s=Z} n = n
|
||||
first {s=S n} (f, r) = f
|
||||
|
||||
lst : { s : Nat } -> Tuple s -> Nat
|
||||
lst {s=Z} n = n
|
||||
lst {s=S n} (f, r) = lst r
|
||||
|
||||
-- Yeah, yeah, this isn't as specified in the
|
||||
-- homework assingment. But what do you want
|
||||
-- us to do with the "zero" case or the "past the edge" case?
|
||||
-- Return 0? Not pretty.
|
||||
project : Fin (S k) -> Tuple k -> Nat
|
||||
project FZ t = first t
|
||||
project {k=S _} (FS n) (f, r) = project n r
|
21
HomeworkTwo.idr
Normal file
21
HomeworkTwo.idr
Normal file
|
@ -0,0 +1,21 @@
|
|||
module HomeworkOne
|
||||
import Data.Vect
|
||||
|
||||
%default total
|
||||
|
||||
zipW : (a -> b -> c) -> Vect n a -> Vect n b -> Vect n c
|
||||
zipW _ [] [] = []
|
||||
zipW f (x::xs) (y::ys) = f x y :: zipWith f xs ys
|
||||
|
||||
lst : Vect (S n) a -> a
|
||||
lst (x::[]) = x
|
||||
lst (_::x::xs) = lst (x::xs)
|
||||
|
||||
initial : Vect (S n) a -> Vect n a
|
||||
initial (x::[]) = []
|
||||
initial (x1::x2::xs) = x1 :: initial (x2::xs)
|
||||
|
||||
palin : Eq a => Vect n a -> Bool
|
||||
palin [] = True
|
||||
palin [x] = True
|
||||
palin (x1::l@(x2::xs)) = x1 == lst l && (palin $ initial l)
|
Loading…
Reference in New Issue
Block a user