Copyright | © Joachim Breitner 2017 |
---|---|
License | MIT |
Maintainer | mail@joachim-breitner.de |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
A value of type
represents a step in a graph with nodes of type Succs
aa
, or in other words, a node plus the list of its successors.
The Applicative
instance for
is such that the node represented by Succs
aa
is the application of the node of <*>
ba
applied to the node of b
, and (more importantly) the successors modeled by a
are the node of <*>
ba
applied to the succesors of b
in addition to the succesors of a
applied to the node of b
. This way, at most one step is taken.
>>>
(++) <$> Succs "0" ["1","2"] <*> Succs "A" ["B","C"]
Succs "0A" ["1A","2A","0B", "0C"]
>>>
skip x = Succs [x] [[]]
>>>
getSuccs $ (concat <$> traverse skip "Hello")
["ello","Hllo","Helo","Helo","Hell"]
This applicative functor can be useful to define shrink functions for QuickCheck, using the helper
shrinkSuccs x = Succs x (shrink x)
as explained in a StackExchange answer.
Documentation
Succs a [a] |
getCurrent :: Succs t -> t Source #
Returns the represented node
Properties:
getCurrent (pure x) == x
getCurrent (f <*> x) == (getCurrent f) (getCurrent x)
getCurrent (x >>= k) == getCurrent (k (getCurrent x))