Great effort!<div><br></div><div>That is a mammoth patch.</div><div>Could you use git add -p to create 2 commits- one with as much of the refactoring as possible, and the other focusing on the additions?</div><div><br></div>
<div>Greg Weber</div><div><br><div class="gmail_quote">On Sun, Mar 20, 2011 at 7:02 PM, Aur Saraf <span dir="ltr"><<a href="mailto:sonoflilit@gmail.com">sonoflilit@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Tue, Mar 15, 2011 at 2:45 AM, Aur Saraf <<a href="mailto:sonoflilit@gmail.com">sonoflilit@gmail.com</a>> wrote:<br>
> Right now I'm having lots of trouble with the TH code generation. I'll<br>
> post my code once the first unit tests pass - a lot before it would<br>
> actually be useful - to see what you guys say about my methods. Also,<br>
> there's a lot of cleaning up - or at least restyling, but I like to<br>
> think it is cleaning up - of TH.hs, which is useful in general.<br>
<br>
</div>At last, my first unit test passes. I have something to show.<br>
<br>
_join = do<br>
a <- insert $ Person "Aur" 12 Nothing<br>
b <- insert $ Person "Bar" 13 $ Just "Blue"<br>
c <- insert $ Pet a "Mazal" Cat<br>
d <- insert $ Pet b "Sasha" Dog<br>
pets <- selectList [PetOwner $ PersonNameEq "Hanners"] [] 0 0<br>
assertEmpty pets<br>
pets <- selectList [PetOwner $ PersonNameEq "Aur"] [] 0 0<br>
assertNotEmpty pets<br>
return ()<br>
<br>
"BEGIN"<br>
"INSERT INTO \"Person\"(\"name\",\"age\",\"color\") VALUES(?,?,?)"<br>
"SELECT last_insert_rowid()"<br>
"INSERT INTO \"Person\"(\"name\",\"age\",\"color\") VALUES(?,?,?)"<br>
"SELECT last_insert_rowid()"<br>
"INSERT INTO \"Pet\"(\"owner\",\"nick\",\"type\") VALUES(?,?,?)"<br>
"SELECT last_insert_rowid()"<br>
"INSERT INTO \"Pet\"(\"owner\",\"nick\",\"type\") VALUES(?,?,?)"<br>
"SELECT last_insert_rowid()"<br>
"SELECT \"Pet\".\"id\",\"Pet\".\"owner\",\"Pet\".\"nick\",\"Pet\".\"type\"<br>
FROM \"Pet\" INNER JOIN \"Person\" ON<br>
\"Person\".\"id\"=\"Pet\".\"owner\" WHERE \"Person\".\"name\"=?"<br>
"SELECT \"Pet\".\"id\",\"Pet\".\"owner\",\"Pet\".\"nick\",\"Pet\".\"type\"<br>
FROM \"Pet\" INNER JOIN \"Person\" ON<br>
\"Person\".\"id\"=\"Pet\".\"owner\" WHERE \"Person\".\"name\"=?"<br>
"COMMIT"<br>
"INSERT INTO \"Person\"(\"name\",\"age\",\"color\") VALUES(?,?,?) RETURNING id"<br>
"INSERT INTO \"Person\"(\"name\",\"age\",\"color\") VALUES(?,?,?) RETURNING id"<br>
"INSERT INTO \"Pet\"(\"owner\",\"nick\",\"type\") VALUES(?,?,?) RETURNING id"<br>
"INSERT INTO \"Pet\"(\"owner\",\"nick\",\"type\") VALUES(?,?,?) RETURNING id"<br>
"SELECT \"Pet\".\"id\",\"Pet\".\"owner\",\"Pet\".\"nick\",\"Pet\".\"type\"<br>
FROM \"Pet\" INNER JOIN \"Person\" ON<br>
\"Person\".\"id\"=\"Pet\".\"owner\" WHERE \"Person\".\"name\"=?"<br>
"SELECT \"Pet\".\"id\",\"Pet\".\"owner\",\"Pet\".\"nick\",\"Pet\".\"type\"<br>
FROM \"Pet\" INNER JOIN \"Person\" ON<br>
\"Person\".\"id\"=\"Pet\".\"owner\" WHERE \"Person\".\"name\"=?"<br>
"BEGIN"<br>
"DELETE FROM \"Pet\""<br>
"DELETE FROM \"Person\""<br>
"COMMIT"<br>
"DELETE FROM \"Pet\""<br>
"DELETE FROM \"Person\""<br>
<br>
join: [OK]<br>
<br>
<br>
<br>
The code is sketchier than an etch-a-sketch-sketch. But it is a place<br>
to start playing from.<br>
<br>
<br>
It can be found at <a href="https://github.com/SonOfLilit/persistent" target="_blank">https://github.com/SonOfLilit/persistent</a>, in the<br>
branch template-haskell-refactoring. It is a fork from<br>
kaoskorobase/persistent, to enjoy the work he did on separating the TH<br>
to a separate package.<br>
<br>
I'll say again: This is very experimental code, it doesn't work in all<br>
- or most - cases, but it shows the way, or at least one way. It can<br>
probably be made to work reasonably well with little work. I'll be<br>
very happy for any comments or patches cleaning up my code, since this<br>
is the most advanced Haskell that I've had the opportunity to write<br>
and many a time I found myself working by guessing or by brute force.<br>
<br>
Also, Michael, you might want to port some refactoring that I did to<br>
the TH code that in my opinion makes it easier to work with, although<br>
I am sure I over-did it, so apply some thought to it before taking<br>
everything.<br>
<br>
Somehow it happened that this whole thing is one huge commit. I wanted<br>
it to compile before I commited, and the test needed a lot of new<br>
features to compile, and it kinda dragged away into days of work<br>
without commiting... Kids, don't do this at home. I shouldn't have.<br>
<br>
I'll be very glad for some code review, I feel it is long due. I'm in<br>
deeper water than I know how to navigate.<br>
<font color="#888888"><br>
<br>
-- Aur<br>
</font></blockquote></div><br></div>