0

I am getting an error that I don't understand. The library I am using has this function:

getComputedStyle ::
             (MonadIO m, IsElement element, ToJSString pseudoElement) =>
               Window ->
                 Maybe element ->
                   Maybe pseudoElement -> m (Maybe CSSStyleDeclaration)

When I call it like this:

Window.getComputedStyle window (Just element) Nothing

I get this error:

Could not deduce (GHCJS.DOM.Types.ToJSString pseudoElement0)
  arising from a use of ‘getComputedStyle’
from the context (Control.Monad.IO.Class.MonadIO m,
                  IsElement element)
  bound by the inferred type of
           isBold :: (Control.Monad.IO.Class.MonadIO m, IsElement element) =>
                     Window -> element -> m (Maybe CSSStyleDeclaration)
  at src/Main.hs:(39,1)-(40,61)
The type variable ‘pseudoElement0’ is ambiguous
Note: there are several potential instances:
  instance GHCJS.DOM.Types.ToJSString
             ghcjs-base-0.2.0.0:Data.JSString.Internal.Type.JSString

    -- Defined in ‘GHCJS.DOM.Types’
  instance GHCJS.DOM.Types.ToJSString
      ghcjs-base-0.2.0.0:Data.JSString.Internal.Type.JSString
    -- Defined in ‘GHCJS.DOM.Types’
  instance GHCJS.DOM.Types.ToJSString
             text-1.2.1.1:Data.Text.Internal.Text
    -- Defined in ‘GHCJS.DOM.Types’
  instance GHCJS.DOM.Types.ToJSString [Char]

    -- Defined in ‘GHCJS.DOM.Types’
 ...

Why does the compiler care about the type? I passed it a Nothing value so the type of the Just value is not really relevant.

michaelmesser
  • 3,601
  • 2
  • 19
  • 42
  • Search stack overflow for other problems with ambiguous types. Long story short: that's a pretty bad API you're using. – Thomas M. DuBuisson Aug 02 '16 at 23:47
  • @ThomasM.DuBuisson any better DOM parsers that have innerText, querySelectorAll, and getComputedStyle? – michaelmesser Aug 02 '16 at 23:54
  • I don't know any DOM parsers at all! But any API that has a Maybe parameter that can't be inferred from other types is bound to cause ambiguous types, as with the literal `Nothing`. For now you'll just have to suffer through giving it an explicit type `(Nothing :: Maybe SOMETHING)`. – Thomas M. DuBuisson Aug 03 '16 at 00:02
  • @ThomasM.DuBuisson ok thanks – michaelmesser Aug 03 '16 at 00:04
  • 5
    `instance Foo (Maybe Int) where foo _ = "Int"; instance Foo (Maybe Char) where foo _ = "Char"`. What is `foo Nothing`? – Gurkenglas Aug 03 '16 at 00:06

0 Answers0