[Haskell-cafe] Deduce issue.

Magicloud Magiclouds magicloud.magiclouds at gmail.com
Tue Jul 29 06:29:29 UTC 2014


Hi,

  I have code like follow. And compiling gave me error as the last part.
What should I do?

```
class WidgetClass w
data Widget = forall a. WidgetClass a => Widget a
instance WidgetClass Widget

lookupWin :: (WidgetClass w) => WINDOW -> w -> Maybe w
lookupWin xwin widget =
  if widgetWindowId widget == xwin
  then Just widget
  else foldl (\a (Widget b) ->
               maybe (lookupWin xwin b) Just a
             ) Nothing $ widgetChildren widget
```
---
```
Graphics/HUI/Widget.hs:15:23:
    Could not deduce (w ~ a)
    from the context (WidgetClass w)
      bound by the type signature for
                 lookupWin :: WidgetClass w => WINDOW -> w -> Maybe w
      at Graphics/HUI/Widget.hs:10:14-54
    or from (WidgetClass a)
      bound by a pattern with constructor
                 Widget :: forall a. WidgetClass a => a -> Widget,
               in a lambda abstraction
      at Graphics/HUI/Widget.hs:14:19-26
      ‘w’ is a rigid type variable bound by
          the type signature for
            lookupWin :: WidgetClass w => WINDOW -> w -> Maybe w
          at Graphics/HUI/Widget.hs:10:14
      ‘a’ is a rigid type variable bound by
          a pattern with constructor
            Widget :: forall a. WidgetClass a => a -> Widget,
          in a lambda abstraction
          at Graphics/HUI/Widget.hs:14:19
    Expected type: Maybe w
      Actual type: Maybe a
    Relevant bindings include
      b :: a (bound at Graphics/HUI/Widget.hs:14:26)
      a :: Maybe w (bound at Graphics/HUI/Widget.hs:14:16)
      widget :: w (bound at Graphics/HUI/Widget.hs:11:16)
      lookupWin :: WINDOW -> w -> Maybe w
        (bound at Graphics/HUI/Widget.hs:11:1)
    In the first argument of ‘maybe’, namely ‘(lookupWin xwin b)’
    In the expression: maybe (lookupWin xwin b) Just a
```
-- 
竹密岂妨流水过
山高哪阻野云飞

And for G+, please use magiclouds#gmail.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140729/0ddfab32/attachment.html>


More information about the Haskell-Cafe mailing list