did you figure out what was wrong with that piece of code?
the code i posted actually works. the whole problem was, that I was writing a local definition for that instead of a function by itself (with a type signature, the q :: forall. part). Without the type signature, haskell persistent was going crazy about the types. I can probably clean that up quite a bit today. I need to do several of those functions to retrieve statistics on various routes: organizations, users, forums, boards, threads, thread posts etc.

So this is how my life is going to look.
probably not, unless you eventually get into functional programming..
that's a SQL (postgresql) query written in a haskell DSL called Esqueleto ;f Haskell uses lots of symbols and such, which can look confusing if you don't know what they mean.
i'm writing the forum etc in haskell (backend) & purescript (frontend), two purely functional programming languages. Haskell has given me the most fun of any programming language, but, it's also been the hardest to learn. It has a nice initial simple learning curve in regards to the basics.. but then, to actually become pro with it, the learning curve is steep.
it's alot of fun though.. more-so than programming in other langs, IMHO. So eventually this forum will be written in haskell + purescript, for the first draft. When haskell improves their full-stack libs (ghcjs), i'll consider porting the front-end to haskell, even though I love purescript. The problem with using two languages is, I have to write my types/structures in both languages.. so there's lots of redundancy there. If I write a User { name :: String, age :: Int } in haskell, I have to do the exact same thing in purescript. There are actually tools now which can auto-generate purescript types from haskell types, but, not to my liking (yet). Full-stack haskell would be alot more efficient.
That code above can be cleaned up to:
q :: forall site.
(YesodPersist site, YesodPersistBackend site ~ SqlBackend) =>
Key Board -> HandlerT site IO [(Value Int64, Value Int64, Value Int64)]
q board_id = do
runDB
$ select
$ from $ \(thread_post `E.LeftOuterJoin` thread `E.LeftOuterJoin` board) -> do
on $ thread ^. ThreadBoardId ==. board ^. BoardId
on $ thread_post ^. ThreadPostThreadId ==. thread ^. ThreadId
where_ $ board ^. BoardId ==. val board_id
return (countDistinct $ board ^. BoardId, countDistinct $ thread ^. ThreadId, countDistinct $ thread_post ^. ThreadPostId)
not too much cleaner but.. easier on the eyes than before.
pc!
edit: I had to modify it slightly because of the whitespace issue in forum posts.. new forum actually has 'codecs': raw, bbcode, code, other etc.. so, will have no issue pasting code. ;f