gliptak
gliptak

Reputation: 3670

define type as Monad

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

Upvotes: 2

Views: 332

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198014

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)

Upvotes: 6

Related Questions