Created
May 20, 2017 07:21
-
-
Save anton-trunov/4394f3edf07a9ccc930e454491a2e257 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- http://stackoverflow.com/questions/44079181/idris-vect-fromlist-usage-with-generated-list | |
total | |
takeExact : (n : Nat) -> (xs : List a) -> Maybe (Vect n a) | |
takeExact Z xs = Just [] | |
takeExact (S n) [] = Nothing | |
takeExact (S n) (x :: xs) with (takeExact n xs) | |
takeExact (S n) (x :: xs) | Nothing = Nothing | |
takeExact (S n) (x :: xs) | (Just v) = Just (x :: v) | |
total | |
window : (n : Nat) -> List a -> List (Vect n a) | |
window n xs with (takeExact n xs) | |
window n xs | Nothing = [] | |
window n [] | (Just ys) = [] | |
window n (x :: xs) | (Just ys) = ys :: window n xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment