<div dir="ltr"><div>The reason you need the typeclass constraint is not in the use of 'f' but rather in the use of propagate and what you pass in to it (foo1/foo2 here). If you leave away the typeclass constraint what you're left with is:<br>
<br>propagate' Bar -> (forall a. a->a) -> Bar<br><br></div>The implementation of this function is the same as before, however your use of propagate' is restricted:<br><div>forall a. a->a is a very "strict" type, in fact the only inhabitant of this type is 'id' (and bottom, but disregard that here), which means the only way to call propagate is to pass in 'id'. Try it yourself!<br>
<br></div><div>Related note: there is a proof that in fact the only inhabitant of (forall a. a -> a) is 'id' and it is the consequence of the "parametricity" property. It is a very neat result I suggest you look it up!<br>
</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 2 December 2013 22:28, TP <span dir="ltr"><<a href="mailto:paratribulations@free.fr" target="_blank">paratribulations@free.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">TP wrote:<br>
<br>
> propagate :: Bar -> (forall a. (FooClass a) => a->a) -> Bar<br>
<br>
</div>In fact, I do not understand why we have to add the typeclass constraint<br>
(FooClass a).<br>
Indeed, there is no mention to foo1 and foo2 functions (members of the<br>
FooClass typeclass) in the code of propagate:<br>
<br>
-------<br>
<div class="im">propagate v f = case v of<br>
        Bar1 i     -> Bar1 (f i)<br>
</div><div class="im">        Exp1 b1 b2 -> Exp1 (propagate b1 f) (propagate b2 f)<br>
        Exp2 b1 b2 -> Exp2 (propagate b1 f) (propagate b2 f)<br>
</div>-------<br>
<br>
propagate deals with any function a priori, not only foo1 and foo2. So how<br>
to understand the need for this typeclass constraint?<br>
<span class="HOEnZb"><font color="#888888"><br>
TP<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div>