我有来自 purescript-express 的以下代码(但问题更笼统)。
setHandler :: forall e. Handler e
setHandler = do
idParam <- getRouteParam "id"
send "Yeah! "
appSetup :: forall e. App e
appSetup = do
get "/set/:id" setHandler
setHandler
需要具有get
定义为的给定签名
> :t get
forall e r.
(RoutePattern r) => r
-> HandlerM ( express :: EXPRESS | e ) Unit
-> AppM ( express :: EXPRESS | e ) Unit
但是现在我想在其中使用以下功能setHandler
getPointsSet :: forall f. String -> Aff ( fs :: FS | f ) Foobar
这会给我以下编译器错误
[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
我知道getPointsSet
有效地使用需要 setHandler 也成为 a Aff
,但我无法将它与get
then 连接起来。
编辑
如果我尝试按照liftAff
以下答案中的建议添加
setHandler :: forall e. Handler e
setHandler = do
idParam <- getRouteParam "id"
liftAff $ getPointsSet "../some-data.csv"
send "Yeah! "
我收到以下错误
[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
我需要做什么来解决这个问题?