Solve homework one and two

这个提交包含在:
Danila Fedorin 2021-01-09 21:31:07 -08:00
当前提交 399e30f085
共有 2 个文件被更改,包括 45 次插入0 次删除

24
HomeworkOne.idr 普通文件
查看文件

@ -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 普通文件
查看文件

@ -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)