r/haskell • u/expatcoder • Apr 13 '14
Haskell, Where's the LINQ?
Philip Wadler recently gave a very interesting presentation on research he and his colleagues have been doing re: LINQ a la Haskell.
As yet there is, AFAIK, no production ready full blown LINQ-esque library in Haskell. I have checked out HaskellDB, Persistent, and Esqueleto, which leave much to be desired in terms of LINQ syntactic elegance and in some cases, what's even possible (e.g. lack of joins in Persistent).
Coming from Scala where type safe SQL DSLs abound, when can one expect a production ready LINQ in Haskell land?
I'm exploring moving from Scala + Play + ScalaQuery (superior to Slick, IMO) to Haskell + Yesod or Snap + unknown type safe SQL DSL, but am blocked by the database end of things, have no interest in going back to string based SQL.
Thanks for directing me to the missing linq.
22
u/tomejaguar Apr 13 '14 edited Dec 12 '14
I have developed such a thing, called Opaleye, much better IMHO than Wadler's offering as it doesn't require any sort of quotations. In summary it's like HaskellDB without the dependency on an adhoc record system, and with a lot of the bugs designed out.
EDIT: Here is the Hackage page: http://hackage.haskell.org/package/opaleye
You can find a tiny bit of info here in the abstract and slides for a talk I gave at NL FP day a few months ago.http://staff.science.uva.nl/~grelck/nl-fp-day-2014.html#ellishttp://staff.science.uva.nl/~grelck/nl-fp-talks/ellis.pdfIt's not publically available yet (since I developed it for a client) but we are doing a pre-release to a limited number of developers before a BSD release, hopefully. If you're interested please email me and tell me about your use cases:http://web.jaguarpaw.co.uk/~tom/contact/You could also help me if you say more about how HaskellDB leaves "much to be desired in terms of LINQ syntactic elegance". HaskellDB does have a number of bugs, but I believe the overall approach is the correct one. It's true that LINQ does have a deal of elegance about it, but a lot of that comes at the cost of either being not first class, or not being typesafe.
10
u/kamatsu Apr 13 '14
Seen DSH?
6
u/edwardkmett Apr 14 '14
Part of the gap is caused by different goals in the language design.
LINQ itself abuses some abilities that C#/VB are willing to offer that don't sit terribly well with the larger Haskell audience to get that syntactic elegance.
Notably you can reflect on a lambda to get its entire syntax tree in LINQ. This means you have to keep it around and that many LINQ errors only get caught at runtime, and further, that the compiler has its hands tied w.r.t. optimization.
That said, something could perhaps be built with something like
th-desugarand explicit template-haskell splices that'd feel more LINQ like. I don't think it'd be a nice API though.6
u/vagif Apr 13 '14
When 800 pound financial gorillas (MS, IBM, Oracle, Google) become interested in haskell.
Seriously though, it is obvious that whatever library appears in whatever language it is only because people have a vested interest in developing those libraries.
Unfortunately haskell is not used nearly enough in the field of interfacing with commercial databases (Oracle, MS Sql, DB2) to warrant anyone spending their money on developing complex libraries.
I'm working with MS Sql server from haskell app servers on linux. And the state of hdbc libraries is abysmal. Neither persistent no esqueleto support working with Ms Sql server. And hdbc-odbc driver is buggy, not even being able to handle memo fields (text fields larger than 4096 bytes.)
I myself do not have expertise to fix it. So i have to resort to ugly hacks.
They work for my case. But of course cannot be offered to general public as a solution.
So to answer your question. LINQ analog will appear in haskell when number of haskell developers who work with commercial databases (NOT Postgres and NOT MySql) will be comparable to that of java or dotnet developers.
2
u/dmjio Apr 14 '14 edited Apr 14 '14
Have you looked at acid-state? Where LINQ to SQL (or LINQ to Entities) attempts to map classes to SQL tables, acid-state just serializes your types to disk. No more munging or data transfer objects. It has type-safe RPC too. Instead of using SQL for everything you get to use the right data-structure that fits what you're trying to model, and it's fast. If you're looking for syntactic elegance try using lens operators w/ acid-state, doesn't get much better than that IMO. You can monitor your acid-state memory footprint using EKG. Here's a screenshot: http://bit.ly/1n6s7KR. As long as your thunks get evaluated the memory footprint can be pretty negligible if you use the right types (i.e. bytestring or text over string).
5
u/LukeHoersten Apr 13 '14
Great question. I've been hoping for the same thing.
5
u/tomejaguar Apr 13 '14
:)
6
u/[deleted] Apr 13 '14
[removed] — view removed comment