Skip to content

Instantly share code, notes, and snippets.

@spockz
Created March 25, 2010 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spockz/344124 to your computer and use it in GitHub Desktop.
Save spockz/344124 to your computer and use it in GitHub Desktop.
type Square = Square' Nil
data Square' t a = Zero (t (t a)) | Succ (Square' (Cons t) a)
data Nil a = Nil deriving Show
data Cons t a = Cons a (t a) deriving Show
mapNil :: (a -> b) -> Nil a -> Nil b
mapNil _ _ = Nil
mapCons :: ((a -> b) -> (t a -> t b))
-> (a -> b)
-> (Cons t a -> Cons t b)
mapCons fT fA (Cons x xs) = Cons (fA x) (fT fA xs)
mapSquare' :: (forall b. (a -> b) -> (t a -> t b))
-> (a -> b)
-> (Square' t a -> Square' t b)
mapSquare' fT fA (Zero xs) = fT (fT fA) xs
mapSquare' fT fA (Succ xs) = mapSquare' (mapCons fT) fA xs
-- Yields:
Ass5.lhs:134:31:
Occurs check: cannot construct the infinite type: t = Cons t
In the first argument of `mapSquare'', namely `(mapCons fT)'
In the expression: mapSquare' (mapCons fT) fA xs
In the definition of `mapSquare'':
mapSquare' fT fA (Succ xs) = mapSquare' (mapCons fT) fA xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment