<div dir="ltr"><div><div><div>Off the top of my head i can think of two non-overlapping solution, both are ugly but maybe someone has an idea to make one nice:<br><br></div>The first is to bake the constraint into the GADT:<br>
<br>data MyGADT a where<br>   MyField :: NFData b => b -> MyGADT (Maybe b)<br><br>instance NFData (MyGADT a) where<br>   rnf (MyField b) = rnf b<br><br></div><div>This is bad because NFData should have nothing to do with the definition of the datastructure<br>
</div><div><br></div>The second is to use implication constraints:<br><br>import Data.Constraint<br><br>data MyGADT a where<br>   MyField :: b -> MyGADT (Maybe b)<br><br>newtype Constr a = Constr (forall b. (a ~ Maybe b) :- NFData b)<br>
<br>class DConstr a where<br>    constr :: Constr a<br><br>instance (NFData a) => DConstr (Maybe a) where<br>    constr = Constr (Sub Dict)<br><br>instance (DConstr a) => NFData (MyGADT a) where<br>   rnf (MyField b) = case constr :: Constr a of<br>
                       Constr (Sub Dict) -> rnf b<br><br><br></div>this is ugly because for every non-Maybe index you need to define an "absurd" instance of DConstr. e.g. for Int:<br><br>instance DConstr Int where<br>
    constr = Constr undefined -- should be (Constr (Sub !absurd!)) but there is no way to denote absurdity in Haskell<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 19 January 2014 23:16, Bob Ippolito <span dir="ltr"><<a href="mailto:bob@redivi.com" target="_blank">bob@redivi.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">For that to work, I believe you must enable FlexibleInstances and possibly also OverlappingInstances (depending on what the rest of the GADT looks like).</div>
<div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">
On Sun, Jan 19, 2014 at 3:00 PM, Carter Schonwald <span dir="ltr"><<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div class="h5">
Try <div><br></div><div><i style="background-color:rgba(255,255,255,0)"><font>instance NFData a => NFData (MyGADT (Maybe a) )<span></span></font></i><div><div><br><br>On Sunday, January 19, 2014, Corentin Dupont <<a href="mailto:corentin.dupont@gmail.com" target="_blank">corentin.dupont@gmail.com</a>> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div>Hi,<br></div>I've tried the make an instance of NFData for all types, although I have a problem with the GATD:<br>


<br><br><i>data MyGADT a where<br>   MyField :: b -> MyGADT (Maybe b)<br>
<br>instance NFData a => NFData (MyGADT a) where<br>   rnf (MyField b) = (rnf b)<br></i><br></div>Gives me :<br>    Could not deduce (NFData b) arising from a use of `rnf'<br>    from the context (NFData a)<br><br>



</div>Which I understand (that's because a ~ <i>Maybe b </i>and not<i> a ~ b </i>due to the declaration of <i>MyField b </i>being of type<i> </i><i><i>MyGADT (Maybe b)</i></i>)<i><br></i></div><i>But I have no idea how to solve that??<br>



</i></div><i>Thanks...<br></i></div><i>Corentin<br></i><div><div><div><div><div><div><br></div></div></div></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jan 13, 2014 at 1:10 AM, Brandon Allbery <span dir="ltr"><<a>allbery.b@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 class="gmail_extra"><div class="gmail_quote"><div>On Sun, Jan 12, 2014 at 6:44 PM, Corentin Dupont <span dir="ltr"><<a>corentin.dupont@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>One question:<br></div>Since it works with putStrLn, can I simulate the behaviour of putStrLn without actually... printing anything? As a workaround...</div>




</blockquote><div><br></div></div><div>Worst case, open a handle on /dev/null and hPutStr to it.</div><div><br></div><div>I'd probably try to figure out how to write appropriate NFData instances, though.</div><div><br>



</div>
</div><div>-- <br><div dir="ltr"><div>brandon s allbery kf8nh                               sine nomine associates</div><div><a>allbery.b@gmail.com</a>                                  <a>ballbery@sinenomine.net</a></div>




<div>unix, openafs, kerberos, infrastructure, xmonad        <a href="http://sinenomine.net" target="_blank">http://sinenomine.net</a></div></div>
</div></div></div>
</blockquote></div><br></div>
</blockquote></div></div></div>
<br></div></div><div class="im">_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">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>
<br></div></blockquote></div><br></div>
<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>
<br></blockquote></div><br></div>