0

Trying to call Eff from within Aff:

import Prelude
import Control.Monad.Aff (Aff, launchAff)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Control.Monad.Eff.Exception (EXCEPTION)

f :: forall eff. Int -> Aff (exception :: EXCEPTION) String
f i = pure $ show i

g :: forall eff. Eff (console :: CONSOLE, exception :: EXCEPTION) Unit
g = void $ launchAff do
  s <- f 1
  liftEff $ log s

This gets me to duplicate:

  Could not match type

    ( exception :: EXCEPTION
    , exception :: EXCEPTION
    )

  with type

    ( console :: CONSOLE
    , exception :: EXCEPTION
    , exception :: EXCEPTION
    )


while trying to match type Eff
                             ( exception :: EXCEPTION
                             , exception :: EXCEPTION
                             )
  with type Eff
              ( console :: CONSOLE
              , exception :: EXCEPTION
              )
while checking that expression (apply void) (launchAff ((bind (...)) (\$0 ->
                                                                        ...
                                                                     )
                                                       )
                                            )
  has type Eff
             ( console :: CONSOLE
             , exception :: EXCEPTION
             )
             Unit
in value declaration g

What should I do? Using purescript version 0.11.3.

levant pied
  • 3,886
  • 5
  • 37
  • 56

1 Answers1

0

This is because of the type of launchAff, which does not include the exception label in its input row. One solution is to include the label twice in the result of g:

forall eff. Eff ( console :: CONSOLE
                , exception :: EXCEPTION
                , exception :: EXCEPTION
                ) Unit

but this means you need to use catchException twice outside launchAff, which is not very natural.

Another is to remove the label using catchException inside the call to launchAff.

A third option is to report a bug on the purescript-aff repo, and to try to change the type of launchAff.

Phil Freeman
  • 4,199
  • 1
  • 20
  • 15