Skip to content

Instantly share code, notes, and snippets.

@flazz
Created August 27, 2013 14:50
Show Gist options
  • Save flazz/6354572 to your computer and use it in GitHub Desktop.
Save flazz/6354572 to your computer and use it in GitHub Desktop.
free monad list, uses product type
import Control.Monad.Free
import Test.QuickCheck
-- tuple based free list
type Nil = ()
nilWitness = ()
data Pair a b = Pair a b
type Ftor = Pair
--type Ftor a = (,) a
type TList a = Free (Ftor a) Nil
toL :: TList a -> [a]
toL (Pure nilWitness) = []
toL (Free (Pair a next)) = a : (toL next)
fromL :: [a] -> TList a
fromL [] = Pure nilWitness
fromL (x:xs) = Free (Pair x (fromL xs))
-- quickCheck (\l -> (toL . fromL $ l) == l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment