<div dir="ltr"><div><div><a href="http://lpaste.net/1333635401797074944">http://lpaste.net/1333635401797074944</a> is one way to use gunfold.<br><br></div>A few years ago, gunfold was error for Data.Map. If there were other abstract data types that had gunfold = error "gunfold", generating a VarE/ConE would be better because the failure would be at compile time instead of at run time.<br><br></div>Adam<br><div><div><br><div class="gmail_extra"><div class="gmail_quote">On Tue, May 5, 2015 at 12:18 PM, Edward Z. Yang <span dir="ltr"><<a href="mailto:ezyang@mit.edu" target="_blank">ezyang@mit.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Michael,<br>
<br>
The Data instance for Map is a very interesting one indeed. Honestly, I<br>
really hate this instance, and I really hate generating a VarE, in part<br>
because there is no guarantee that fromList is defined in the same<br>
module as the type definition.<br>
<br>
But it gives a valuable clue about how dataToQa: maybe it's wrong for us<br>
to try to directly make names based on the Constr information that is<br>
given to us: instead, the generate TH code should be a call to /gunfold/<br>
(with TH lifting the Constr). Of course, this would be even more<br>
inefficient, but maybe the optimizer can figure it out.<br>
Unfortunately, I don't actually know how to encode an arbitrary<br>
constructor invocation indirected through Data.<br>
<br>
Edward<br>
<br>
Excerpts from Michael Sloan's message of 2015-04-18 12:50:39 -0700:<br>
<div class="HOEnZb"><div class="h5">> +1 to liftData<br>
><br>
> Removing 'Lift' altogether definitely isn't the way to go, though. As<br>
> Richard points out, we want to be able to lift more than just ADTs. Also<br>
> ADTs which hide their implementation can have either opaque Data instances,<br>
> no Data instance, or Data instances which involve using functions for<br>
> constructors.<br>
><br>
> An example of the latter is Data.Map.Map's Data instance, which uses<br>
> 'fromList' as a constructor. This results in $(dataToExpQ (\_ -> Nothing)<br>
> (fromList [(1,2)])) causing the compiletime error "Illegal data constructor<br>
> name: ‘fromList’".<br>
><br>
> I think 'dataToExpQ' and related functions should be modified to handle<br>
> this case. It should be rather easy - if the constructor Name is<br>
> lowercase, generate a 'VarE' instead of a 'ConE'. I suppose this is a<br>
> separate proposal, but it came up when thinking about this proposal.<br>
><br>
> -Michael<br>
><br>
> On Fri, Apr 17, 2015 at 4:21 AM, Edward Z. Yang <<a href="mailto:ezyang@mit.edu">ezyang@mit.edu</a>> wrote:<br>
><br>
> > I propose adding the following function to <a href="http://Language.Haskell.TH" target="_blank">Language.Haskell.TH</a>:<br>
> ><br>
> > -- | 'liftData' is a variant of 'lift' in the 'Lift' type class which<br>
> > -- works for any type with a 'Data' instance.<br>
> > liftData :: Data a => a -> Q Exp<br>
> > liftData = dataToExpQ (const Nothing)<br>
> ><br>
> > I don't really know which submodule this should come from;<br>
> > since it uses 'dataToExpQ', you might put it in Language.Haskell.TH.Quote<br>
> > but arguably 'dataToExpQ' doesn't belong in this module either,<br>
> > and it only lives there because it is a useful function for defining<br>
> > quasiquoters and it was described in the quasiquoting paper.<br>
> ><br>
> > I might propose getting rid of the 'Lift' class entirely, but you<br>
> > might prefer that class since it doesn't go through SYB (and have<br>
> > the attendant slowdown).<br>
> ><br>
> > This mode of use of 'dataToExpQ' deserves more attention.<br>
> ><br>
> > Discussion period: 1 month<br>
> ><br>
> > Cheers,<br>
> > Edward<br>
> > _______________________________________________<br>
> > Libraries mailing list<br>
> > <a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
> > <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
> ><br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</div></div></blockquote></div><br></div></div></div></div>