<p>What about</p>
<p>data Foo = X { a :: Int }<br>
data FooLifted = XLifted { aLifted :: Maybe Int }</p>
<p>As I indicated earlier. Sorry for not being more eloquent on my phone.<br></p>
<p>Aristid </p>
<div class="gmail_quote">Am 06.05.2011 11:48 schrieb &quot;Michael Snoyman&quot; &lt;<a href="mailto:michael@snoyman.com">michael@snoyman.com</a>&gt;:<br type="attribution">&gt; So a quick review: we have a few general approaches here:<br>
&gt; <br>&gt; 1) Create a few different datatypes, or a single datatype with<br>&gt; multiple constructors.<br>&gt; 2) Somehow annotate the fields to indicate that data may or may not be present.<br>&gt; 3) Fill in some dummy values for fields not loaded.<br>
&gt; <br>&gt; I think option (1) is by far the most type safe. It&#39;s also the most<br>&gt; involved and unintuitive. Greg&#39;s point about multiple constructors<br>&gt; being ugly is very true. And two datatypes will be hard to manage.<br>
&gt; <br>&gt; Option (2) will work, but it&#39;s significantly less type safe. There&#39;s<br>&gt; nothing at the type level distinguishing &quot;get&quot; and &quot;getPartial&quot;. And<br>&gt; it will have a strongly negative impact on all code branches using<br>
&gt; &quot;get&quot;.<br>&gt; <br>&gt; Option (3) is not as type-safe as option (1). In it&#39;s scariest form,<br>&gt; it&#39;s going to allow undefined to float around programs wreaking havoc.<br>&gt; In its more benign form, it will simply allow the user to provide<br>
&gt; dummy values. The downside versus option (1) is that there&#39;s nothing<br>&gt; at the type level distinguishing get from getPartial. The downside<br>&gt; versus option (2) is that there is nothing at the value level<br>
&gt; distinguishing get from getPartial.<br>&gt; <br>&gt; But the advantage of (3) is that it&#39;s much simpler to implement and<br>&gt; will have no effect on regular code at all. I think it&#39;s also much<br>&gt; easier to understand how to use it to someone.<br>
&gt; <br>&gt; Anyone see something I&#39;m missing?<br>&gt; <br>&gt; Michael<br>&gt; <br>&gt; On Fri, May 6, 2011 at 7:49 AM, Aristid Breitkreuz<br>&gt; &lt;<a href="mailto:aristidb@googlemail.com">aristidb@googlemail.com</a>&gt; wrote:<br>
&gt;&gt; How about generating a version of the records lifted to Maybe?<br>&gt;&gt;<br>&gt;&gt; Am 06.05.2011 04:03 schrieb &quot;Max Cantor&quot; &lt;<a href="mailto:mxcantor@gmail.com">mxcantor@gmail.com</a>&gt;:<br>&gt;&gt;&gt; Personally, I vote against this. Putting in undefineds maintains<br>
&gt;&gt;&gt; type-safety. However, in my mind the primary purpose of static type-safety<br>&gt;&gt;&gt; is the avoidance of runtime errors. This only encourages that. Perhaps a<br>&gt;&gt;&gt; better approach is to have some a TH function to generate &quot;subselects&quot; which<br>
&gt;&gt;&gt; would be records that only contain the requested data. Its a bit more<br>&gt;&gt;&gt; constraining, but I fear that the alternative is tantamount to curing the<br>&gt;&gt;&gt; disease by killing the patient.<br>
&gt;&gt;&gt;<br>&gt;&gt;&gt; furthermore, I worry that allowing undefined&#39;s here will start a slippery,<br>&gt;&gt;&gt; runtime-error-laden slope which we&#39;re better off avoiding..<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; max<br>
&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; On May 5, 2011, at 9:55 PM, Michael Snoyman wrote:<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; That&#39;s interesting: I&#39;d never considered the idea of inserting<br>
&gt;&gt;&gt;&gt; undefined into fields you want excluded... That could work. The reason<br>&gt;&gt;&gt;&gt; I&#39;ve avoided putting in this (often requested) feature is that I could<br>&gt;&gt;&gt;&gt; think of no way to do so and keep type safety. That might be an<br>
&gt;&gt;&gt;&gt; approach.<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; We may consider requiring the user to supply the value instead,<br>&gt;&gt;&gt;&gt; thereby avoiding the library inserting undefined.<br>&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Michael<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; On Thu, May 5, 2011 at 4:32 PM, Greg Weber &lt;<a href="mailto:greg@gregweber.info">greg@gregweber.info</a>&gt; wrote:<br>&gt;&gt;&gt;&gt;&gt; An alternative to laziness would be selecting a subset of fields. There<br>
&gt;&gt;&gt;&gt;&gt; is<br>&gt;&gt;&gt;&gt;&gt; no support for this directly in persistent, but it might be possible to<br>&gt;&gt;&gt;&gt;&gt; add<br>&gt;&gt;&gt;&gt;&gt; it and the future and have the value of an unselected field be something<br>
&gt;&gt;&gt;&gt;&gt; like undefined.<br>&gt;&gt;&gt;&gt;&gt; At the moment you can select sub fields by dropping down to lower-level<br>&gt;&gt;&gt;&gt;&gt; sql<br>&gt;&gt;&gt;&gt;&gt; methods (ask Michael about these methods if you are interested). I think<br>
&gt;&gt;&gt;&gt;&gt; there is a technique for building your persistent data structure back up<br>&gt;&gt;&gt;&gt;&gt; from the return of raw sql, which again you might be able to do by<br>&gt;&gt;&gt;&gt;&gt; inserting<br>
&gt;&gt;&gt;&gt;&gt; dummy error fields.<br>&gt;&gt;&gt;&gt;&gt; Greg Weber<br>&gt;&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;&gt; On Thu, May 5, 2011 at 4:18 AM, Michael Snoyman &lt;<a href="mailto:michael@snoyman.com">michael@snoyman.com</a>&gt;<br>
&gt;&gt;&gt;&gt;&gt; wrote:<br>&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;&gt;&gt; On Thu, May 5, 2011 at 1:28 PM, Felipe Almeida Lessa<br>&gt;&gt;&gt;&gt;&gt;&gt; &lt;<a href="mailto:felipe.lessa@gmail.com">felipe.lessa@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; On Thu, May 5, 2011 at 2:20 AM, Jeremy Hughes &lt;<a href="mailto:jedahu@gmail.com">jedahu@gmail.com</a>&gt;<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; wrote:<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Is Database.Persistent lazy wrt reading fields? I need to iterate<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; over<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; entities containing both small and large fields. I do not need to use<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; the large fields in this instance, and so would rather they were not<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; read from the database.<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; IIRC, they are read strictly. I guess you should put them on a<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; different entity.<br>
&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;&gt;&gt; That&#39;s correct. In fact, Persistent avoids any form of lazy I/O to<br>&gt;&gt;&gt;&gt;&gt;&gt; ensure that database connections are returned to the pool as soon as<br>
&gt;&gt;&gt;&gt;&gt;&gt; possible (amongst other reasons).<br>&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;&gt;&gt; Michael<br>&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt;&gt;&gt;&gt; web-devel mailing list<br>&gt;&gt;&gt;&gt;&gt;&gt; <a href="mailto:web-devel@haskell.org">web-devel@haskell.org</a><br>&gt;&gt;&gt;&gt;&gt;&gt; <a href="http://www.haskell.org/mailman/listinfo/web-devel">http://www.haskell.org/mailman/listinfo/web-devel</a><br>
&gt;&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; _______________________________________________<br>&gt;&gt;&gt;&gt; web-devel mailing list<br>&gt;&gt;&gt;&gt; <a href="mailto:web-devel@haskell.org">web-devel@haskell.org</a><br>
&gt;&gt;&gt;&gt; <a href="http://www.haskell.org/mailman/listinfo/web-devel">http://www.haskell.org/mailman/listinfo/web-devel</a><br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; web-devel mailing list<br>&gt;&gt;&gt; <a href="mailto:web-devel@haskell.org">web-devel@haskell.org</a><br>&gt;&gt;&gt; <a href="http://www.haskell.org/mailman/listinfo/web-devel">http://www.haskell.org/mailman/listinfo/web-devel</a><br>
&gt;&gt;<br></div>