Skip to content

Instantly share code, notes, and snippets.

@conal
Last active August 29, 2015 14:18
Show Gist options
  • Save conal/69529e6b93c1ad7d8e19 to your computer and use it in GitHub Desktop.
Save conal/69529e6b93c1ad7d8e19 to your computer and use it in GitHub Desktop.
Isomorphism between streams and function-of-Nat
{-# 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