我正在尝试使用extensible-skeleton
包。在另一个效果中堆叠效果会导致编译错误。我尝试了一些其他语言扩展和类型注释,但无法删除这些错误。如何解决这些错误?
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Main where
import Data.Extensible
import Data.Extensible.Effect
import Data.Type.Equality
type In0 effs = Lookup effs "io" IO
type In1 effs = Lookup effs "reader-float" (ReaderEff Double)
run0 :: forall a. Eff '["io" >: IO] a -> IO a
run0 = retractEff
run1 :: forall effs a. Double -> Eff (("reader-float" >: ReaderEff Double) ': effs) a -> Eff effs a
run1 x = peelEff0 pure $ \Refl k -> k x
lift0 :: forall effs a. In0 effs => IO a -> Eff effs a
lift0 = liftEff (Proxy :: Proxy "io")
ask1 :: forall effs. In1 effs => Eff effs Double
ask1 = askEff (Proxy :: Proxy "reader-float")
eff0 :: forall effs. In0 effs => Eff effs ()
eff0 = do
lift0 $ print "eff0"
run1 2.5 eff1
eff1 :: forall effs. (In0 effs, In1 effs) => Eff effs ()
eff1 = do
x <- ask1
lift0 $ print "eff1"
lift0 $ print (floor x)
main :: IO ()
main = do
run0 eff0
编译时的错误:
[1 of 2] Compiling Main
app/Main.hs:32:12: error:
• Couldn't match type ‘membership-0:Type.Membership.Internal.Elaborate
"io" (membership-0:Type.Membership.Internal.FindAssoc 1 "io" effs)’
with ‘'membership-0:Type.Membership.Internal.Expecting (n0 ':> IO)’
arising from a use of ‘eff1’
The type variable ‘n0’ is ambiguous
• In the second argument of ‘run1’, namely ‘eff1’
In a stmt of a 'do' block: run1 2.5 eff1
In the expression:
do lift0 $ print "eff0"
run1 2.5 eff1
• Relevant bindings include
eff0 :: Eff effs () (bound at app/Main.hs:30:1)
|
32 | run1 2.5 eff1
| ^^^^
怎么了?