I have the following code from purescript-express (but the question is more general).
setHandler :: forall e. Handler e
setHandler = do
idParam <- getRouteParam "id"
send "Yeah! "
appSetup :: forall e. App e
appSetup = do
get "/set/:id" setHandler
setHandler
needs to have the given signature as get
is defined as
> :t get
forall e r.
(RoutePattern r) => r
-> HandlerM ( express :: EXPRESS | e ) Unit
-> AppM ( express :: EXPRESS | e ) Unit
Now however I want to use the following function within setHandler
getPointsSet :: forall f. String -> Aff ( fs :: FS | f ) Foobar
which will give me the following compiler error
[1/1 TypesDoNotUnify] src/Main.purs:31:5
v
31 send "Yeah! "
^
Could not match type
HandlerM
with type
Aff
while trying to match type HandlerM
( express :: EXPRESS
| _2
)
with type Aff
( fs :: FS
| _0
)
while checking that expression send "Yeah! "
has type Aff
( fs :: FS
| _0
)
_1
in value declaration setHandler
I understand that using getPointsSet
effectively requires setHandler to become a Aff
as well but than I cannot wire it up with the get
then.
Edit
If I try to add a liftAff
as suggested in the answer below
setHandler :: forall e. Handler e
setHandler = do
idParam <- getRouteParam "id"
liftAff $ getPointsSet "../some-data.csv"
send "Yeah! "
I get the following error
[1/1 NoInstanceFound] src/Main.purs:28:1
28 setHandler :: forall e. Handler e
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
No type class instance was found for
Control.Monad.Aff.Class.MonadAff ( fs :: FS | _0 )
(HandlerM ( express :: EXPRESS | e0 ))
The instance head contains unknown type variables. Consider adding a type annotation.
in value declaration setHandler
What do I need to do to resolve that?