Created
September 9, 2016 16:55
-
-
Save jfdm/751a44887d24dfa0f743fb7472290421 to your computer and use it in GitHub Desktop.
MFE for Idris regression.
This file contains hidden or 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
| module Data.DList | |
| using (aTy : Type, elemTy : (aTy -> Type), x : aTy) | |
| ||| A list construct for dependent types. | |
| ||| | |
| ||| @aTy The type of the value contained within the list element type. | |
| ||| @elemTy The type of the elements within the list | |
| ||| @as The List used to contain the different values within the type. | |
| public export | |
| data DList : (aTy : Type) | |
| -> (elemTy : aTy -> Type) | |
| -> (as : List aTy) | |
| -> Type where | |
| ||| Create an empty List | |
| Nil : DList aTy elemTy Nil | |
| ||| Cons | |
| ||| | |
| ||| @elem The element to add | |
| ||| @rest The list for `elem` to be added to. | |
| (::) : (elem : elemTy x) | |
| -> (rest : DList aTy elemTy xs) | |
| -> DList aTy elemTy (x::xs) | |
| span : ({a : aTy} -> elemTy a -> Bool) | |
| -> DList aTy elemTy xys | |
| -> ((xs ** DList aTy elemTy xs), (ys ** DList aTy elemTy ys)) | |
| span f Nil = ((_ ** Nil), (_ ** Nil)) | |
| span f (x::xs) = | |
| if f x | |
| then let ((_ ** ys),(_ ** zs)) = span f xs | |
| in ((_ ** x::ys), (_ ** zs)) | |
| else ((_ ** Nil), (_ ** (x::xs))) | |
| break : ({a : aTy} -> elemTy a -> Bool) | |
| -> DList aTy elemTy xys | |
| -> ((xs ** DList aTy elemTy xs), (ys ** DList aTy elemTy ys)) | |
| break f xs = span (not . f) xs | |
| split : ({a : aTy} -> elemTy a -> Bool) | |
| -> DList aTy elemTy xys | |
| -> (xxs ** DList (List aTy) (\xs => DList aTy elemTy xs) xxs) | |
| split f xs = | |
| case break f xs of | |
| ((_ ** chunk), (_ ** Nil)) => (_ ** [chunk]) | |
| ((_ ** chunk), (_ ** (y::ys))) => let (_ ** rest) = DList.split f ys | |
| in (_ ** DList.(::) chunk rest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment