In the module below, function g compiles without no comment but function f gives the message "Could not match type", with the explanation that (err :: Exception | e) does not match ().
However, both throwException and toISOString return a value in Eff with the EXCEPTION effect (and possibly others).
It looks as if catchException does not remove the EXCEPTION effect in f, but does remove the effect in g. Indeed, the inferred type for f is:
f :: forall e. DateTime -> Eff (err :: EXCEPTION | e) String
Why is this?
module Problem.With.Exception where
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (catchException, throwException, error)
import Data.DateTime (DateTime(..))
import Data.JSDate (fromDateTime, toISOString)
import Prelude (pure, ($), (<>), show, discard, bind)
g :: DateTime -> Eff () String
g d = catchException
(\_ -> pure "Some message")
(throwException $ error "Bla")
-- This is the inferred type for f:
-- f :: forall e. DateTime -> Eff (err :: EXCEPTION | e) String
-- But this is the type I hope for:
f :: DateTime -> Eff () String
f d = catchException
(\_ -> pure "Some message")
(toISOString (fromDateTime d))