2

I'm trying to run the code from:

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.39.8039&rep=rep1&type=pdf

using ghci 7.6.3

{-# LANGUAGE LiberalTypeSynonyms, TypeSynonymInstances #-}
type C m a = (a -> Action m) -> Action m
data Action m = Atom (m (Action m)) | Fork (Action m) (Action m) | Stop

This original form:

instance (Monad m) => Monad (C m) where
   f >>= k = \c -> f (\a -> k a c)
   return x = \c -> c x

gives this error:

Type synonym `C' should have 2 arguments, but has been given 1
In the instance declaration for `Monad (C m)'

Trying with the additional argument:

instance (Monad m) => Monad (C m b) where
   f >>= k = \c -> f (\a -> k a c)
   return x = \c -> c x

shows this error:

Kind mis-match
The first argument of `Monad' should have kind `* -> *',
but `C m b' has kind `*'
In the instance declaration for `Monad (C m b)'

How to correct this definition? Thanks

gliptak
  • 3,592
  • 2
  • 29
  • 61
  • 1
    http://stackoverflow.com/questions/16273896/implementing-this-monad-type-in-haskell http://stackoverflow.com/questions/24881351/why-cant-you-totally-apply-a-type-synonym-that-has-arguments-using-an-other-t – gliptak Dec 25 '14 at 16:22
  • `C m` is `Cont (Action m)`, so you should just use Cont here (and if you want to see how that works, just look at the source for Cont). – user2407038 Dec 26 '14 at 05:07

1 Answers1

6

Partially applied type synonyms can't be type class instances, and the only way to avoid that in this case is to make this a data or newtype declaration.

You will have to change the definition of C to make this work to e.g.

newtype C m a = C ((a -> Action m) -> Action m)
Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413