0
votes

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))
1

1 Answers

1
votes

I tried it in a clean environment, and the module compiled as is (with the expected type, no EXCEPTION effect). I think you may have some library/code version problems. Maybe you want to do

rm -rf node_modules
rm -rf bower_components
npm install
bower install
pulp build

I have the following library versions in package.json:

"devDependencies": {
  "bower": "^1.8.2",
  "pulp": "^12.0.1",
  "purescript": "^0.11.7"
}

And these in bower.json:

"dependencies": {
  "purescript-prelude": "^3.1.1",
  "purescript-console": "^3.0.0",
  "purescript-exceptions": "^3.1.0",
  "purescript-js-date": "^5.1.0",
  "purescript-datetime": "^3.4.1"
},
"devDependencies": {
  "purescript-psci-support": "^3.0.0"
}