Haskell beam constraints - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Sridhar Ratnakumar

tfw when constraints are longer than the function body image.png

Sandy Maguire

each of those constraints is writing code for you :)

Mats Rauhala

I'm not a friend of beam, but tbh, those constraints tell me more about what the function does than the implementation

Torsten Schmits

@Mats Rauhala why do you not like Beam? what do you prefer?

Mats Rauhala

I would just go with postgres simple.

  • The added complexity of beam is non trivial. I would argue that the benefit doesn't outweigh the cost
  • so far I haven't used even the first orm, relational algebra, DSL, edsl etc that wouldn't have at some point leaked the abstraction, or support some necessary part of sql, or generated horrible sql etc
Mats Rauhala

Instead, I endorse writing a simple function with a clean type and writing some tests for it.

addPerson :: WithDB r m => Person -> m ()

Mats Rauhala

Of course, when your purpose is to learn something new or have fun, go with what you want

Torsten Schmits

ok, I have only used Hasql so far, I guess that comes with a similar cost

Ben Kolera

Yeah, hasql is nicer than PG simple in my eyes. Not abusing typeclasses for encoding / decoding stuff makes it pretty excellent and painless to deal with. :heart:

Torsten Schmits

yes, that's a positive aspect I also noticed when perusing the Beam docs.
I've been playing around with deriving Row and Params for my types, which works pretty fine, but it's a bit tedious that I can't (afaict) simply run those codecs for testing

Torsten Schmits

my experience with codecs has often been that it's undesirable when the data type has to incorporate stuff for derivation in its fields, like the Columnar in Beam

Torsten Schmits

though I still use generics-sop, so that's kind of similar, only more general

Torsten Schmits

though looking at my code now I realize that the most significant parts of the derivations deal with the constructions of statements, the codecs are rather trivial

Mats Rauhala

You know, hasql is not something I've ever really tried. IIRC you still write raw sql queries on it, but define the encoders/decoders with functors / contravariant functors instead of typeclasses. So I would liken it with postgresql-simple. The full power of SQL with the type safety of haskell where it matters the most.

Personally I haven't had any pain with having type classes as encoders (like psql, aeson, quickcheck), but I've seen plenty of people having pain with it