Created
December 21, 2015 14:57
-
-
Save gallais/0ee7d3e2b60e3bcedcc4 to your computer and use it in GitHub Desktop.
Unfold function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ScopedTypeVariables #-} | |
module UnfoldTree where | |
data Tree v e = Node v [(e,Tree v e)] | |
unfold :: forall s v e. (s -> (v, [(e,s)])) -> s -> Tree v e | |
unfold next seed = uncurry Node $ fmap rec $ next seed where | |
rec :: [(e,s)] -> [(e, Tree v e)] | |
rec = fmap $ fmap (unfold next) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment