Maintainer | bastiaan.heeren@ou.nl |
---|---|
Stability | provisional |
Portability | portable (depends on ghc) |
Safe Haskell | None |
Language | Haskell98 |
This module defines views on data-types, as described in "Canonical Forms in Interactive Exercise Assistants"
- class Category * a => Arrow a where
- class Arrow a => ArrowChoice a where
- class Arrow a => ArrowZero a where
- zeroArrow :: a b c
- class ArrowZero a => ArrowPlus a where
- (<+>) :: a b c -> a b c -> a b c
- (>>>) :: Category k cat => cat a b -> cat b c -> cat a c
- (<<<) :: Category k cat => cat b c -> cat a b -> cat a c
- class IsMatcher f where
- matchM :: (Monad m, IsMatcher f) => f a b -> a -> m b
- belongsTo :: IsMatcher f => a -> f a b -> Bool
- viewEquivalent :: (IsMatcher f, Eq b) => f a b -> a -> a -> Bool
- viewEquivalentWith :: IsMatcher f => (b -> b -> Bool) -> f a b -> a -> a -> Bool
- data Matcher a b
- makeMatcher :: (a -> Maybe b) -> Matcher a b
- class IsMatcher f => IsView f where
- simplify :: IsView f => f a b -> a -> a
- simplifyWith :: IsView f => (b -> b) -> f a b -> a -> a
- simplifyWithM :: IsView f => (b -> Maybe b) -> f a b -> a -> a
- canonical :: IsView f => f a b -> a -> Maybe a
- canonicalWith :: IsView f => (b -> b) -> f a b -> a -> Maybe a
- canonicalWithM :: IsView f => (b -> Maybe b) -> f a b -> a -> Maybe a
- isCanonical :: (IsView f, Eq a) => f a b -> a -> Bool
- isCanonicalWith :: IsView f => (a -> a -> Bool) -> f a b -> a -> Bool
- data View a b
- identity :: Category f => f a a
- makeView :: (a -> Maybe b) -> (b -> a) -> View a b
- matcherView :: Matcher a b -> (b -> a) -> View a b
- data Isomorphism a b
- from :: Isomorphism a b -> a -> b
- to :: Isomorphism a b -> b -> a
- inverse :: Isomorphism a b -> Isomorphism b a
- class LiftView f where
- liftView :: View a b -> f b -> f a
- liftViewIn :: View a (b, c) -> f b -> f a
- swapView :: Isomorphism (a, b) (b, a)
- listView :: View a b -> View [a] [b]
- traverseView :: Traversable f => View a b -> View (f a) (f b)
- ($<) :: Traversable f => View a (f b) -> View b c -> View a (f c)
- data ViewPackage where
- ViewPackage :: (Show a, Show b, Eq a) => (String -> Maybe a) -> View a b -> ViewPackage
- propIdempotence :: (Show a, Eq a) => Gen a -> View a b -> Property
- propSoundness :: Show a => (a -> a -> Bool) -> Gen a -> View a c -> Property
- propNormalForm :: (Show a, Eq a) => Gen a -> View a b -> Property
Documentation
class Category * a => Arrow a where
The basic arrow class.
Instances should satisfy the following laws:
arr
id =id
arr
(f >>> g) =arr
f >>>arr
gfirst
(arr
f) =arr
(first
f)first
(f >>> g) =first
f >>>first
gfirst
f >>>arr
fst
=arr
fst
>>> ffirst
f >>>arr
(id
*** g) =arr
(id
*** g) >>>first
ffirst
(first
f) >>>arr
assoc
=arr
assoc
>>>first
f
where
assoc ((a,b),c) = (a,(b,c))
The other combinators have sensible default definitions, which may be overridden for efficiency.
arr :: (b -> c) -> a b c
Lift a function to an arrow.
first :: a b c -> a (b, d) (c, d)
Send the first component of the input through the argument arrow, and copy the rest unchanged to the output.
second :: a b c -> a (d, b) (d, c)
A mirror image of first
.
The default definition may be overridden with a more efficient version if desired.
(***) :: a b c -> a b' c' -> a (b, b') (c, c') infixr 3
Split the input between the two argument arrows and combine their output. Note that this is in general not a functor.
The default definition may be overridden with a more efficient version if desired.
(&&&) :: a b c -> a b c' -> a b (c, c') infixr 3
Fanout: send the input to both argument arrows and combine their output.
The default definition may be overridden with a more efficient version if desired.
class Arrow a => ArrowChoice a where
Choice, for arrows that support it. This class underlies the
if
and case
constructs in arrow notation.
Instances should satisfy the following laws:
left
(arr
f) =arr
(left
f)left
(f >>> g) =left
f >>>left
gf >>>
arr
Left
=arr
Left
>>>left
fleft
f >>>arr
(id
+++ g) =arr
(id
+++ g) >>>left
fleft
(left
f) >>>arr
assocsum
=arr
assocsum
>>>left
f
where
assocsum (Left (Left x)) = Left x assocsum (Left (Right y)) = Right (Left y) assocsum (Right z) = Right (Right z)
The other combinators have sensible default definitions, which may be overridden for efficiency.
left :: a b c -> a (Either b d) (Either c d)
Feed marked inputs through the argument arrow, passing the rest through unchanged to the output.
right :: a b c -> a (Either d b) (Either d c)
A mirror image of left
.
The default definition may be overridden with a more efficient version if desired.
(+++) :: a b c -> a b' c' -> a (Either b b') (Either c c') infixr 2
Split the input between the two argument arrows, retagging and merging their outputs. Note that this is in general not a functor.
The default definition may be overridden with a more efficient version if desired.
(|||) :: a b d -> a c d -> a (Either b c) d infixr 2
Fanin: Split the input between the two argument arrows and merge their outputs.
The default definition may be overridden with a more efficient version if desired.
IsMatch
type class
viewEquivalent :: (IsMatcher f, Eq b) => f a b -> a -> a -> Bool Source
viewEquivalentWith :: IsMatcher f => (b -> b -> Bool) -> f a b -> a -> a -> Bool Source
makeMatcher :: (a -> Maybe b) -> Matcher a b Source
IsView
type class
class IsMatcher f => IsView f where Source
Minimal complete definition: toView
or both match
and build
.
Nothing
simplifyWith :: IsView f => (b -> b) -> f a b -> a -> a Source
simplifyWithM :: IsView f => (b -> Maybe b) -> f a b -> a -> a Source
canonicalWith :: IsView f => (b -> b) -> f a b -> a -> Maybe a Source
canonicalWithM :: IsView f => (b -> Maybe b) -> f a b -> a -> Maybe a Source
isCanonical :: (IsView f, Eq a) => f a b -> a -> Bool Source
isCanonicalWith :: IsView f => (a -> a -> Bool) -> f a b -> a -> Bool Source
Views
matcherView :: Matcher a b -> (b -> a) -> View a b Source
Isomorphisms
data Isomorphism a b Source
from :: Isomorphism a b -> a -> b Source
to :: Isomorphism a b -> b -> a Source
inverse :: Isomorphism a b -> Isomorphism b a Source
Lifting with views
Some combinators
swapView :: Isomorphism (a, b) (b, a) Source
traverseView :: Traversable f => View a b -> View (f a) (f b) Source
Packaging a view
data ViewPackage where Source
ViewPackage :: (Show a, Show b, Eq a) => (String -> Maybe a) -> View a b -> ViewPackage |