Created
August 27, 2013 14:50
-
-
Save flazz/6354572 to your computer and use it in GitHub Desktop.
free monad list, uses product type
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
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