Last active
August 29, 2015 14:18
-
-
Save conal/69529e6b93c1ad7d8e19 to your computer and use it in GitHub Desktop.
Isomorphism between streams and function-of-Nat
This file contains 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
{-# OPTIONS_GHC -Wall #-} | |
module NatStream where | |
data Nat = Zero | Succ Nat | |
data Stream a = a :< Stream a | |
-- Stream is the trie induced by Nat. | |
-- Here's the isomorphism, explicitly: | |
toFun :: Stream a -> (Nat -> a) | |
toFun (a :< _ ) Zero = a | |
toFun (_ :< as) (Succ n) = toFun as n | |
toStream :: (Nat -> a) -> Stream a | |
toStream f = f Zero :< toStream (f . Succ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment