Skip to content

Instantly share code, notes, and snippets.

@gallais
Created February 22, 2015 00:26
Show Gist options
  • Save gallais/6c7c23fe3da69ef1bd71 to your computer and use it in GitHub Desktop.
Save gallais/6c7c23fe3da69ef1bd71 to your computer and use it in GitHub Desktop.
Unfold of a Fix
module Unfold where
newtype Fix f = InFix { outFix :: f (Fix f) }
unfoldFix :: Functor f => (s -> f s) -> s -> Fix f
unfoldFix node = go
where go = InFix . fmap go . node
data ListF a r = LNil | LCons a r
data TreeF a r = TNil | TLeaf a | TBranch r r
type List a = Fix (ListF a)
type Tree a = Fix (TreeF a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment