Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (37 sloc) 1.35 KB

Common Errors

There are certain classes of errors when using fused-effects that GHC is not particularly good at explaining. This document is an attempt to enumerate and explicate the things that can go wrong when using or extending this library. (It is also very much a work in progress.)

I'm getting kind errors when implementing a Carrier instance!

Given a Teletype data type:

data Teletype m k
  = Read (String -> k)
  | Write String k
  deriving (Functor)

newtype TeletypeIOC m a = TeletypeIOC { runTeletypeIOC :: m a }

Declaring a Carrier instance will fail:

instance (Carrier sig m, Effect sig)
    => Carrier (Teletype :+: sig) (TeletypeIOC m) where
• Expected kind ‘(* -> *) -> * -> *’,
    but ‘Teletype :+: sig’ has kind ‘* -> * -> *’
• In the first argument of ‘Carrier’, namely ‘(Teletype :+: sig)’
  In the instance declaration for
    ‘Carrier (Teletype :+: sig) (TeletypeIOC m)

This is because the m parameter to Teletype is inferred to be of kind *: though Carrier expects an m of kind * -> *, m is never referenced in the definition of Teletype, so GHC makes an understandable but incorrect inference. An explicit kind annotation on m fixes the problem.

data Teletype (m :: * -> *) k
  = Read (String -> k)
  | Write String k
  deriving (Functor)
You can’t perform that action at this time.