Created
April 7, 2014 06:48
-
-
Save co-dan/10015772 to your computer and use it in GitHub Desktop.
Sequence-algebras
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
{-# LANGUAGE TypeFamilies, FlexibleInstances #-} | |
module SeqFoldable where | |
import Prelude hiding (drop, take) | |
import Data.Functor.Foldable | |
import Data.Sequence (Seq, ViewL (..), (<|)) | |
import qualified Data.Sequence as S | |
data instance Prim (Seq a) b = EmptyP | ViewP a b | |
instance Functor (Prim (Seq a)) where | |
fmap _ EmptyP = EmptyP | |
fmap f (ViewP a b) = ViewP a (f b) | |
type instance Base (Seq a) = Prim (Seq a) | |
viewlToPrim :: ViewL a -> Prim (Seq a) (Seq a) | |
viewlToPrim EmptyL = EmptyP | |
viewlToPrim (a :< as) = ViewP a as | |
instance Foldable (Seq a) where | |
project = viewlToPrim . S.viewl | |
instance Unfoldable (Seq a) where | |
embed EmptyP = S.empty | |
embed (ViewP a b) = a <| b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment