
TypeSynonymInstances isn't doing anything you couldn't do yourself.
It's just expanding the type synonym in the instance declaration for
you.
In this case, the error is because type synonyms must be fully
applied. However, your type synonym can be eta-contracted:
type SomeMonad = ErrorT String (ReaderT String IO)
Now you can use it in an instance declaration. But this doesn't work
in general; this type synonym cannot be made into a monad:
type St s a = s -> (a,s)
However, I think that adding instances this way is bad style. I
suggest turning on newtype deriving instead, and doing:
newtype SomeMonad a = SomeMonad (ErrorT String (Reader T String IO) a)
deriving (Monad, MonadError, MonadReader String, MonadIO, Functor)
instance Applicative SomeMonad where
pure = return
(<*>) = ap
-- ryan
On Mon, Mar 15, 2010 at 2:34 PM, Vasyl Pasternak
Hello,
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 error:
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 ?
Thanks, Vasyl _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe