Skip to content

Instantly share code, notes, and snippets.

@gip
Last active August 29, 2015 14:07
Show Gist options
  • Save gip/82aee58d0eb76a61e077 to your computer and use it in GitHub Desktop.
Save gip/82aee58d0eb76a61e077 to your computer and use it in GitHub Desktop.
Haskell / Free Monad / How can I do something like this?
data A = A Text
data B = B Text A
data ActionC t next = InsertC t (t -> next)
instance Functor (ActionC t) where
fmap f (InsertC a b)= InsertC a (f . b)
insertC a = liftF (InsertC a id)
proC txt1 txt2 = do
a <- insertC $ A txt1
b <- insertC $ B txt2 a
return b
@gip
Copy link
Author

gip commented Oct 14, 2014

I get the error:
Couldn't match type A' withB'
When using functional dependencies to combine
MonadFree (ActionC A) m0,
arising from a use of insertC' at Transact.hs:96:8-14 MonadFree (ActionC B) m0, arising from a use ofinsertC' at Transact.hs:97:8-14
In the expression: insertC
In a stmt of a 'do' block: b <- insertC $ B txt2 a

How can I fix this so that it compiles?

@mioalter
Copy link

I think you want 'String' in place of 'Text' in your definitions of A and B.
Not in scope: type constructor or class `Text'
Don't know if it does what you want, but it compiles when I make that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment