Copyright | © Joachim Breitner 2017 |
---|---|

License | MIT |

Maintainer | mail@joachim-breitner.de |

Safe Haskell | Safe |

Language | Haskell2010 |

A value of type

represents a step in a graph with nodes of type `Succs`

a`a`

, or in other words, a node plus the list of its successors.

The `Applicative`

instance for

is such that the node represented by `Succs`

a`a `

is the application of the node of `<*>`

b`a`

applied to the node of `b`

, and (more importantly) the successors modeled by `a `

are the node of `<*>`

b`a`

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 "0A" ["1A","2A","0B", "0C"]`(++) <$> Succs "0" ["1","2"] <*> Succs "A" ["B","C"]`

`>>>`

`skip x = Succs [x] [[]]`

`>>>`

["ello","Hllo","Helo","Helo","Hell"]`getSuccs $ (concat <$> traverse skip "Hello")`

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))