Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# Language RankNTypes, MultiParamTypeClasses #-}
- module Data.Nonempty where
- import Data.Functor.Identity
- import Control.FIFO.FIFO
- import Control.Unfoldable.Unfoldable
- import Control.Traversable.Traversable
- infixr 5 :|
- data Nonempty a = a :| Nonempty a | End a deriving (Show,Eq, Ord)
- --
- instance Foldable0' Nonempty where
- foldMap0' = foldMap0'Default
- instance Get0 Nonempty where
- get0 = get0Default
- instance Unfoldable0 Nonempty
- instance Set0 Nonempty where
- set0 = set0Default
- instance Stream Nonempty
- --
- instance Foldable1' Nonempty where
- foldMap1' = foldMap1'Default
- instance Get1 Nonempty where
- get1 (x :| xs) = (x,Just xs)
- get1 (End x) = (x,Nothing)
- instance Unfoldable1 Nonempty where
- unfoldr1 = unfoldr1Default
- instance Set1 Nonempty where
- set1 (x,Just xs) = (x :| xs)
- set1 (x,Nothing) = (End x)
- instance Traversable1' Nonempty where
- traverse1' = convert1
- instance Linear Nonempty
- instance Functor' Nonempty where
- fmap' = fmap'Default
- instance Foldable' Nonempty where
- foldMap' = foldMap'Default
- instance Traversable' Nonempty where
- traverse' = traverse'Default'
- --
- test :: Nonempty Int
- test = unfoldr1 10 (\n -> if n == 0 then (n,Nothing) else (n,Just (n-1)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement