[Haskell-cafe] Deduce issue.

Magicloud Magiclouds magicloud.magiclouds at gmail.com
Tue Jul 29 07:04:10 UTC 2014


I can see this is because of existential type used in Widget. But removing
it would make a lot of other types using a type var for no reason.


On Tue, Jul 29, 2014 at 2:31 PM, Magicloud Magiclouds <
magicloud.magiclouds at gmail.com> wrote:

> Sorry, missed a line of `class WidgetClass w`.
>
> ```
> class WidgetClass w where
>   widgetChildren :: w -> [Widget]
> ```
>
>
> On Tue, Jul 29, 2014 at 2:29 PM, Magicloud Magiclouds <
> magicloud.magiclouds at gmail.com> wrote:
>
>> 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.
>>
>
>
>
> --
> 竹密岂妨流水过
> 山高哪阻野云飞
>
> And for G+, please use magiclouds#gmail.com.
>



-- 
竹密岂妨流水过
山高哪阻野云飞

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/8218e493/attachment.html>


More information about the Haskell-Cafe mailing list