diff options
author | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2017-02-14 14:59:39 -0500 |
---|---|---|
committer | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2017-02-14 14:59:39 -0500 |
commit | f18fdcb2e0d1ef4ce1cf5892dec99909126af129 (patch) | |
tree | 538e6dfdef2b27e19529263d28733636d4d1a1a8 | |
parent | 6aa16c40df3cd44b8a6d47f6153e28c892f4dee9 (diff) |
splitAt = take, drop proof
-rw-r--r-- | Ch10.idr | 25 |
1 files changed, 15 insertions, 10 deletions
@@ -3,18 +3,23 @@ module Ch10 data TakeN : List a -> Type where Fewer : TakeN xs Exact : (n_xs : List a) -> TakeN (n_xs ++ rest) - + +splitStep : a -> (List a, List a) -> (List a, List a) +splitStep x (xs, ys) = (x :: xs, ys) + mySplit : (n : Nat) -> (input : List a) -> (List a, List a) mySplit n [] = ([], []) mySplit Z xs = ([], xs) -mySplit (S k) (x :: xs) = let (this, rest) = (mySplit k xs) in - (x :: this, rest) - -mySplit_keeps_list : (n : Nat) -> (input : List a) -> - mySplit n input = (as, bs) -> as ++ bs = input -mySplit_keeps_list Z [] Refl = Refl -mySplit_keeps_list (S k) [] Refl = Refl -mySplit_keeps_list Z (x :: xs) Refl = Refl -mySplit_keeps_list (S k) (x :: xs) prf = ?hole -- ???? +mySplit (S k) (x :: xs) = splitStep x (mySplit k xs) + +mySplitIsTakeDrop : (n : Nat) -> (input : List a) -> + mySplit n input = (take n input, drop n input) +mySplitIsTakeDrop Z [] = Refl +mySplitIsTakeDrop Z (x::xs) = Refl +mySplitIsTakeDrop Z [] = Refl +mySplitIsTakeDrop (S k) [] = Refl +mySplitIsTakeDrop (S k) (x::xs) = + let rec = mySplitIsTakeDrop k xs in + rewrite rec in Refl takeN : (n : Nat) -> (input : List a) -> TakeN input |