0
votes

I have following code snippet from haskell book:

embedded' :: MaybeT (ExceptT String (ReaderT () IO)) Int
embedded' = MaybeT (ExceptT (ReaderT (const (return (Right (Just 1))))))

The type signature of ExceptT is as follow:

newtype ExceptT e m a =
  ExceptT { runExceptT :: m (Either e a)) }

Compare the type signature of the embedded' function with ExceptT type constructor:

        ExceptT   e             m                 a
                  |             |                 |
MaybeT (ExceptT String   (ReaderT () IO) (**missing here**)  ) Int

How can I just leave ExceptT as higher kinded?

I tried also:

fullType :: ExceptT String []
fullType = undefined

the compiler complains:

* Expecting one more argument to `ExceptT String []'
  Expected a type, but `ExceptT String []' has kind `* -> *'
* In the type signature:
    fullType :: ExceptT String []

Failed, modules loaded: none.

2
I didn't quite get what's missing. The a is Int in your case. - arrowd
The MaybeT obtains a type of kind * -> *, and an a, Int and applies a to * -> *. - Willem Van Onsem

2 Answers

3
votes

You probably got confused by outmost MaybeT. This type is parametrised by 2 arguments of kinds m :: * -> * and a :: *, respectively. So, that ExceptT String (ReaderT () IO) is indeed missing an a because it is an MaybeT first argument and should be of kind * -> *. Had we apply Int to ExceptT, it would turn into * and then it can't be passed to MaybeT.

0
votes

Disclaimer: I am not with my Haskell environment, so this might be utter nonsense.

Put in an explicit type variable for the missing spot on ExceptT:

embedded' :: MaybeT (ExceptT String (ReaderT () IO) a) Int
embedded' = MaybeT (ExceptT (ReaderT (const (return (Right (Just 1))))))

Hopefully the compiler can figure out what a should be!

What you're running into, which shows more obviously in your fullType example, is that it's not possible to give something a type of kind * -> *. Functions, values and so forth all need to have types of kind *.

Currying a type constructor gives you a * -> *, so you have to provide something for all the parameters.

Putting a type parameter in the signature for embedded' makes it kind *, but polymorphic over a.