lpsmith / postgresql-simple

Mid-level client library for accessing PostgreSQL from Haskell
Other
206 stars 71 forks source link

FromRow (Maybe a) #208

Closed ivan-m closed 7 years ago

ivan-m commented 7 years ago

Is there any particular reason this instance isn't defined?

instance (FromField a) => FromRow (Maybe a) where
  fromRow = field

The lack of this instance is stopping the Generic deriving working for my datatypes; not sure if there's a deliberate reason it's missing though.

ivan-m commented 7 years ago

Nevermind, I found discussions elsewhere about how this (or more specifically, a FromRow a => FromRow (Maybe a) instance) would break other instances (and there are more specific instances available anyway).

Which is a pity, but I guess I have to do a manual FromRow instance of my datatype then.

lpsmith commented 7 years ago

Could you link the discussions? Personally, I'd love to have the FromRow a => FromRow (Maybe a) instance, there are already some less generic instances to that effect, but IIRC the issue isn't so much that it would break anything too important, but rather that one can't implement that with the current interface. (Which would break client code, which is sad, but I'm willing to do that if the change represents actual progress.)

ivan-m commented 7 years ago

There's some discussion on #64, I suppose #178 (which is why just using optional fails) and your announcement for 0.4.2.

andrewthad commented 7 years ago

I think changing the representation only causes problems for users who need to parse a variable number of fields using the instance for [a]. I would personally prefer a representation that tracked how many fields were being consumed, since the current interface is bad for left joins.