Skip to content

Instantly share code, notes, and snippets.

@nulldatamap
Created February 9, 2016 10:21
Show Gist options
  • Select an option

  • Save nulldatamap/575cd5c04ef4024f5a14 to your computer and use it in GitHub Desktop.

Select an option

Save nulldatamap/575cd5c04ef4024f5a14 to your computer and use it in GitHub Desktop.
data Free f a = Free (f (Free f a)) | Pure a
deriving Functor
liftF :: Functor f => f a -> Free f a
liftF action = Free (fmap Pure action)
data Ex x = Ex x (Maybe x)
deriving Functor
ex x y = liftF (Ex x y)
{- Error:
Occurs check: cannot construct the infinite type: a ~ Free Ex a
Expected type: Maybe a
Actual type: Maybe (Free Ex a)
Relevant bindings include
xs :: [a] (bound at src/Free.hs:17:12)
x :: a (bound at src/Free.hs:17:10)
problem :: [a] -> Free Ex a (bound at src/Free.hs:16:1)
In the second argument of ‘($)’, namely ‘Just $ problem xs’
In the expression: ex x $ Just $ problem xs
In an equation for ‘problem’:
problem (x : xs) = ex x $ Just $ problem xs
-}
problem (x:[]) = ex x Nothing
problem (x:xs) = ex x $ Just $ problem xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment