0

这编译

foo ma = case ma of
  [Just a] -> newRVar 0 >>= a

view                :: forall a eff. 
                       M.Map String (Linker Number a eff) -> 
                       String -> 
                       Eff (reactive :: Reactive | eff) Unit
view         m yaml = case parseYAML yaml           of
  Right (View xs)  -> case (flip M.lookup) m <$> xs of
    (as)       -> foo as

这不

foo ma = case ma of
  Just a -> newRVar 0 >>= a

view                :: forall a eff. 
                       M.Map String (Linker Number a eff) -> 
                       String -> 
                       Eff (reactive :: Reactive | eff) Unit
view         m yaml = case parseYAML yaml           of
  Right (View xs)  -> case (flip M.lookup) m <$> xs of
    (as)       -> foo <$> as

出现以下错误:

 Cannot unify Control.Monad.Eff.Eff (reactive :: Control.Reactive.Reactive | u8437) u8438 with Prelude.Unit.

为什么?

4

1 回答 1

1

错误消息告诉您,您将Control.Monad.Eff.Eff (reactive :: Control.Reactive.Reactive | u8437) u8438a放在Unit应该去的地方。

foo有类型声明吗?view由于当前缺乏类型类约束推断,无论您在做什么,它都可能无法在没有它的情况下工作。

在第二种情况下,类型是:

foo :: forall a eff. Maybe a -> Eff (reactive :: Control.Reactive.Reactive | eff) a

的类型(<$>)

(<$>) :: forall f a b. (Functor f) => (a -> b) -> f a -> f b

aswill的类型是Maybe (Linker Number a eff),所以如果你开始替换类型,你可以很快看到哪里出错了:

a ~ Maybe (Linker Number a1 eff)
b ~ Eff (reactive :: Control.Reactive.Reactive | eff) (Linker Number a1 eff)
f ~ Maybe

所以f b结果类型foo <$> as是:

Maybe (Eff (reactive :: Control.Reactive.Reactive | eff) (Linker Number a1 eff))
于 2014-08-08T15:19:06.847 回答