pandora-0.1.4: Pandora/Paradigm/Basis/Edges.hs
module Pandora.Paradigm.Basis.Edges (Edges (..), edges) where
import Pandora.Core.Morphism (($))
import Pandora.Pattern.Functor.Covariant (Covariant ((<$>)))
import Pandora.Pattern.Functor.Pointable (Pointable (point))
import Pandora.Pattern.Functor.Traversable (Traversable ((->>)))
data Edges a = Empty | Connect a | Overlay a
instance Covariant Edges where
_ <$> Empty = Empty
f <$> Connect x = Connect $ f x
f <$> Overlay x = Overlay $ f x
instance Traversable Edges where
Empty ->> _ = point Empty
Connect x ->> f = Connect <$> f x
Overlay x ->> f = Overlay <$> f x
edges :: r -> (a -> r) -> (a -> r) -> Edges a -> r
edges r _ _ Empty = r
edges _ f _ (Connect x) = f x
edges _ _ g (Overlay y) = g y