[web-devel] Database.Persistent
Greg Weber
greg at gregweber.info
Fri May 6 05:31:07 CEST 2011
I can think of 2 other approaches:
1) lazy IO, but don't hold a connection open- accessing a lazy field creates
an entirely new request. This means a change in the type signature of the
field accessor to be in IO.
2) A to be excluded field must be nullable, and excluding it will return a
Nothing. Instead of a runtime failure, you get a runtime wtf? moment if you
don't realize why your data is not being displayed.
I didn't mention TH sub-selects idea because originally I didn't see how it
was practical. Lets say that we force users to declare the possible
sub-selects so that we avoid exponential TH. A first approach is for
sub-selects be of the same data type as the full select.
data Person = PersonAll String String | PersonJustName String
For all your functions that operate on your data, you will now have to
pattern match against all the declared permutations, and some of the pattern
matches are going to result in runtime errors or dummy values. So it seems
they should be different data types. But now we need to have the same
functions operate over different types. So we need a bunch of typeclasses
that define which fields are operated on.
data Person = Person String String
data PersonJustName = Person String
class PersonName p where
personName :: p -> String
instance PersonName Person
personName (Person name _) = name
instance PersonName PersonJustName
personName (Person name) = name
But I really don't know if the different data types means an entire
re-working of Persistent, with even more obscure types. I will let Michael
shoot this down :)
Greg Weber
On Thu, May 5, 2011 at 7:50 PM, Felipe Almeida Lessa <felipe.lessa at gmail.com
> wrote:
> On Thu, May 5, 2011 at 11:35 PM, Ian Duncan <iand675 at gmail.com> wrote:
> > Not sure that I feel *quite* so strongly about it as Max, but I agree
> with
> > his sentiments here. I'm not convinced that a proper implementation that
> > could deal with undefineds would be particularly error-prone, but I
> imagine
> > that performance would be better anyways with TH.
>
> Although undefined isn't nice, it's kind of difficult to provide a TH
> solution. For example, if your entity has 20 fields, would you
> generate all 2^20 different combinations of this-field-is-not-needed
> datatypes? Would the data types be generated on the call site (this
> is impossible, however). So should the user specify on the persistent
> entity declaration that a field may not be needed? Even so, if you
> said that you may not need 6 fields, would you generate 2^6 different
> data types. Or should you tell not only which fields, but also which
> combination of fields? And what names would these data types get?
>
> IOW, this is complicated. =)
>
> The undefined route doesn't seem so bad. Actually, as Michael said,
> we could have the user pass a default value. Then you could use as
> default value 'error "fileX.hs, function foo, field zyw"' or something
> like that, giving you decisive information that you used an undefined
> field, and which field that was.
>
> Cheers,
>
> --
> Felipe.
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110505/535fc2ca/attachment.htm>
More information about the web-devel
mailing list