<div dir="ltr">I should just use Widget I defined. Why not before....<div><br></div><div>But then I am confused on type cast again. How to extract the existential type inside Widget?</div></div><div class="gmail_extra"><br>
<br><div class="gmail_quote">On Tue, Jul 29, 2014 at 3:04 PM, Magicloud Magiclouds <span dir="ltr"><<a href="mailto:magicloud.magiclouds@gmail.com" target="_blank">magicloud.magiclouds@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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.</div>
<div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 29, 2014 at 2:31 PM, Magicloud Magiclouds <span dir="ltr"><<a href="mailto:magicloud.magiclouds@gmail.com" target="_blank">magicloud.magiclouds@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Sorry, missed a line of `class WidgetClass w`.<div><br></div><div>```</div><div>class WidgetClass w where</div>

<div>  widgetChildren :: w -> [Widget]<br></div><div>```</div></div><div><div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Tue, Jul 29, 2014 at 2:29 PM, Magicloud Magiclouds <span dir="ltr"><<a href="mailto:magicloud.magiclouds@gmail.com" target="_blank">magicloud.magiclouds@gmail.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>  I have code like follow. And compiling gave me error as the last part. What should I do?</div>


<div><br></div><div>```</div><div>class WidgetClass w<br></div><div>data Widget = forall a. WidgetClass a => Widget a<br>
</div><div>instance WidgetClass Widget<br></div><div><br></div><div><div>lookupWin :: (WidgetClass w) => WINDOW -> w -> Maybe w</div><div>lookupWin xwin widget =</div><div>  if widgetWindowId widget == xwin</div>



<div>  then Just widget</div><div>  else foldl (\a (Widget b) -></div><div>               maybe (lookupWin xwin b) Just a</div><div>             ) Nothing $ widgetChildren widget</div></div><div>```</div><div>---</div>



<div>```</div><div>Graphics/HUI/Widget.hs:15:23:<br></div><div>    Could not deduce (w ~ a)</div><div>    from the context (WidgetClass w)</div><div>      bound by the type signature for</div><div>                 lookupWin :: WidgetClass w => WINDOW -> w -> Maybe w</div>



<div>      at Graphics/HUI/Widget.hs:10:14-54</div><div>    or from (WidgetClass a)</div><div>      bound by a pattern with constructor</div><div>                 Widget :: forall a. WidgetClass a => a -> Widget,</div>



<div>               in a lambda abstraction</div><div>      at Graphics/HUI/Widget.hs:14:19-26</div><div>      ‘w’ is a rigid type variable bound by</div><div>          the type signature for</div><div>            lookupWin :: WidgetClass w => WINDOW -> w -> Maybe w</div>



<div>          at Graphics/HUI/Widget.hs:10:14</div><div>      ‘a’ is a rigid type variable bound by</div><div>          a pattern with constructor</div><div>            Widget :: forall a. WidgetClass a => a -> Widget,</div>



<div>          in a lambda abstraction</div><div>          at Graphics/HUI/Widget.hs:14:19</div><div>    Expected type: Maybe w</div><div>      Actual type: Maybe a</div><div>    Relevant bindings include</div><div>      b :: a (bound at Graphics/HUI/Widget.hs:14:26)</div>



<div>      a :: Maybe w (bound at Graphics/HUI/Widget.hs:14:16)</div><div>      widget :: w (bound at Graphics/HUI/Widget.hs:11:16)</div><div>      lookupWin :: WINDOW -> w -> Maybe w</div><div>        (bound at Graphics/HUI/Widget.hs:11:1)</div>



<div>    In the first argument of ‘maybe’, namely ‘(lookupWin xwin b)’</div><div>    In the expression: maybe (lookupWin xwin b) Just a</div><div>```</div><span><font color="#888888">-- <br>竹密岂妨流水过<br>山高哪阻野云飞<br>
<br>And for G+, please use magiclouds#<a href="http://gmail.com" target="_blank">gmail.com</a>.
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>竹密岂妨流水过<br>山高哪阻野云飞<br><br>And for G+, please use magiclouds#<a href="http://gmail.com" target="_blank">gmail.com</a>.
</div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>竹密岂妨流水过<br>山高哪阻野云飞<br><br>And for G+, please use magiclouds#<a href="http://gmail.com" target="_blank">gmail.com</a>.
</div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>竹密岂妨流水过<br>山高哪阻野云飞<br><br>And for G+, please use magiclouds#<a href="http://gmail.com" target="_blank">gmail.com</a>.
</div>