News for hackers. Stuff that matters.
Re:Is Haskell the right language for teaching functional pro... by geofft on Monday October 16, 2017 @01:36PM (#15485072)
> What have you learned about FP from executing SQL queries? Probably nothing.

I would really like to know why you conclude this, because it seems almost certainly wrong. SQL is a great example of a mainstream non-imperative, no-implicit-side-effect language, which is really the essence of functional programming.

Re:Is Haskell the right language for teaching functional pro... by hnal943 on Monday October 16, 2017 @02:29PM (#15485507)
Agree. Functional programming made no sense to me until I came back to it after years of writing complex data warehousing SQL.
Re:Is Haskell the right language for teaching functional pro... by NumberCruncher on Monday October 16, 2017 @07:37PM (#15487535)
I am writing SQL/PLSQL for my living and I like how learning Elixir changed the way I accomplish my daily work.
Re:Is Haskell the right language for teaching functional pro... by nightski on Monday October 16, 2017 @02:30PM (#15485520)
Hmm, I'd argue the essence of functional programming is composability of which SQL has very little.
Re:Is Haskell the right language for teaching functional pro... by rjbwork on Monday October 16, 2017 @04:17PM (#15486310)
I would argue that you probably haven't written any SQL of significant complexity in which to observe its composability if that is your assertion. Subqueries, table-valued functions, SProcs that return tables, and more allow you to compose operations into your desired final query.

That said, it is largely used in a giant procedural way most of the time, and is certainly not an ideal functional language, but the fundamentals of things like, map, filter, reduce, sort, etc. are there.

Re:Is Haskell the right language for teaching functional pro... by nightski on Monday October 16, 2017 @04:39PM (#15486478)
I have written quite a bit of SQL including all of the items you mentioned including common table expressions, subqueries, views, etc..

This is a very limited form of composition. It's very difficult to break a query down into a bunch of subcomponents that can be reused among groups of queries. CTEs are close, but it's really hard to achieve re-usability of a CTE unless you are stitching together strings at runtime.

Probably the closest you could get is a view, but even then if you have many views stitched together to form a query this can impact performance in ugly ways.

Generally in order to achieve the best performance and to get the most of out of the DB engine it seems like producing unique SQL for each query which is optimized for that query is generally the optimal approach.

In summary: Just because SQL is based on a few composable operations (map, filter), does not mean it is composable itself.

Re:Is Haskell the right language for teaching functional pro... by geofft on Monday October 16, 2017 @04:58PM (#15486594)
This is a slightly snarky but mostly serious response: isn't hidden runtime complexity of elegant operations also a property of functional programming languages? :-)

There are a few that are good at optimization (and in my limited experience, Haskell is one of them), but in general if you use lots of conceptually clean maps and filters, you will occasionally see cases where your performance is very bad because you don't have full control over exactly what is evaluated when, won't you? That seems like basically the same problem that you have with using views and not trusting your query planner to do things efficiently.

Re:Is Haskell the right language for teaching functional pro... by rjbwork on Monday October 16, 2017 @05:04PM (#15486650)
I can largely agree with that from a practical perspective - I was speaking more in the theoretical. At any kind of practical scale, everything does seem to end up being fairly bespoke.