Skip to content

Instantly share code, notes, and snippets.

@jfdm
Created September 9, 2016 16:55
Show Gist options
  • Select an option

  • Save jfdm/751a44887d24dfa0f743fb7472290421 to your computer and use it in GitHub Desktop.

Select an option

Save jfdm/751a44887d24dfa0f743fb7472290421 to your computer and use it in GitHub Desktop.
MFE for Idris regression.
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