postgresql-simple icon indicating copy to clipboard operation
postgresql-simple copied to clipboard

Generation of tuple instances for FromRow with huge arities using TH macro

Open nikita-volkov opened this issue 11 years ago • 7 comments

This macro is tested to work fine in my personal projects. But after spending an hour trying to integrate it into the maze of internal cyclic dependencies of "postgresql-simple" I gave up. Anyway, I'm still posting this for you to catch on with the integration work.

nikita-volkov avatar Nov 22 '13 15:11 nikita-volkov

Looks good, I'll probably merge this when I get around to fixing it.

I suspect that you don't really need to change the .hs-boot files at all. Those don't include any definitions, just types, and only need to include enough types and instances to break the type-checking cycle, not every type and instance exported from a module.

lpsmith avatar Nov 30 '13 20:11 lpsmith

Ok, looking at it again you do need to tweak the .hs-boot files a bit. I'll look into it at some point.

lpsmith avatar Nov 30 '13 22:11 lpsmith

Ok, I did look at it a bit just now, for probably just over an hour. I must admit, I'm as confused as you are. GHC isn't producing very helpful error messages on this one.

I suspect it's some kind of special interaction between Template Haskell and recursive modules, but I haven't found any write up of these issues. Although the wiki hints that maybe protocol-buffers was up against a similar-ish issue? I'm not sure.

lpsmith avatar Dec 21 '13 13:12 lpsmith

A pity.

nikita-volkov avatar Dec 21 '13 15:12 nikita-volkov

Care to publish it as a separate package? Being able to use native tuples for n > 8 would be splendid. Here's what I've been using so far:

-- | Works almost like '(:.)' for 'ToField' instances. Start with `()`
-- and append as many fields as needed:
--
-- > () :* f1 :* f2 :* f3
--
-- Initial `()` saves the type hassle.
data a :* b = a :* b deriving (Eq, Ord, Show, Read)

infixl 3 :*

instance (ToRow a, ToField b) => ToRow (a :* b) where
    toRow (a :* b) = toRow $ a :. (Only b)

dzhus avatar Feb 09 '14 18:02 dzhus

@dzhus I don't see much reason to. It really should be in the postgresql-simple project. You have my confirmation if you intend to do it yourself however.

It should also be noted that integrating the code in the associated commit into any project is seamless.

nikita-volkov avatar Feb 09 '14 18:02 nikita-volkov

"Closes #91" in the commit above is a typo, unfortunately one that's not easily corrected. That should have been "closes #99".

lpsmith avatar Sep 07 '14 19:09 lpsmith