2017-08-03 59 views
2

有麻烦解开也许和空的值如下:也许嵌套和可空

container <- 
    unsafePartial 
    (fromJust <<< toMaybe 
    <$> DOM.querySelector (DOM.QuerySelector "body") 
    (DOM.htmlDocumentToParentNode document)) 

使我有以下错误:

Could not match type

Maybe

with type

Nullable

while trying to match type Maybe Element
with type Nullable t1
while checking that expression (querySelector (QuerySelector "body"))
(htmlDocumentToParentNode document)
has type t0 (Nullable t1)
in value declaration main

where t0 is an unknown type
t1 is an unknown type

我已经试过,但我无法找到我通过这里使用的各种类型的方式 (代码最初是从here

回答

1

我会建议打破这一点。

开始

do body <- DOM.querySelector (DOM.QuerySelector "body") 
      (DOM.htmlDocumentToParentNode document)) 
    ?whatNext 

这里,?whatNext是一个类型的孔。编译器会告诉你这个洞的推断类型,这应该可以帮助你找出替换它的方法。

另请注意,通过直接应用unsafePartialfromJust,可以简化一些事情,以提供Maybe a -> a类型的功能。

+0

是的,最终我通过应用unsafePartial并从最后一行直接将容器应用于容器来实现它。感谢您通知我输入的洞,看起来非常有用,虽然在这种情况下,它表明usafeCoerce不起作用。 – bensnowball

+0

是的,不是每个建议都可以。这意味着它会进行类型检查。 –