[Haskell-cafe] How to define instance for type synonym with parameter.

Vasyl Pasternak vasyl.pasternak at gmail.com
Mon Mar 15 17:34:05 EDT 2010


I am start with example. Suppose I have the following type synonym:

type SomeMonad a = ErrorT String (ReaderT  String IO) a

this is monad, and I want to make it instance of Applicative, so, the
obvious way is to write the following:

instance Applicative SomeMonad where
  pure = return
  (<*>) = ap

GHCi warns me, that I have to use -XTypeSynonymInstances option to
allow this construction, but than I have following

    Type synonym `SomeMonad' should have 1 argument, but has been given 0
    In the instance declaration for `Applicative SomeMonad'

Neither `instance Applicative (SomeMonad a)` nor `instance Applicative
SomeMonad a` help. But works the following:

instance Applicative (ErrorT String (ReaderT String IO)) where
  pure = return
  (<*>) = ap

Which is the same (from my point of view).

Could anyone tell me what is going on, and how to declare SomeMonad as
instance of Applicative ?


More information about the Haskell-Cafe mailing list