这个编译
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.
为什么?
答案 0 :(得分:1)
错误消息告诉您,您要Control.Monad.Eff.Eff (reactive :: Control.Reactive.Reactive | u8437) u8438
放置一个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
as
的类型将是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))