This is defeating me. Can anyone tell me where I’m going wrong here?
selectFromDocument :: (V (Array String) QuerySelector) -> HTMLDocument -> Effect (V Errors HTMLInputElement)
selectFromDocument (V (Right sel)) doc = do
m <- querySelector sel (toParentNode doc)
pure $ V $ note (Left ("Cannot find element using selector `" <> showQS sel <> "`.")) (m >>= fromElement)
selectFromDocument err _ = pure err
QuerySelector is just a String.
querySelector :: QuerySelector -> ParentNode -> Effect (Maybe Element)
So shouldn’t m
be Maybe Element
? Then:
fromElement :: Element -> Maybe HTMLInputElement
Then shouldn’t bind
return Maybe HTMLInputElement
? Then:
note :: forall a b. a -> Maybe b -> Either a b
And won’t that return an Either
that gets wrapped in a V
and then pure
makes it back into an Effect
?
But I get an error on this line: m <- querySelector sel (toParentNode doc)
that says “Could not match type Effect with type Either t0 while trying to match type Effect (Maybe Element)”. This makes zero sense to me. Can anyone explain?