1

I'm watching some lecture's on Functional Programming and the main 'data structure' so to say, but there really isn't one in FP, is lists, so my question is: when one deals a lot with database's and 'lists' of data, then is Functional Programming not superior to OOP?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
  • http://stackoverflow.com/questions/330371/are-databases-and-functional-programming-at-odds asks the same question with the opposite sense and seems to be well answered. Also related: http://stackoverflow.com/questions/218190/is-functional-to-relational-mapping-easier-than-object-to-relational and – dmckee --- ex-moderator kitten Feb 07 '10 at 21:00

2 Answers2

6

One of the biggest improvements in reading from databases in recent years is LINQ. LINQ is actually based a lot on functional programming principles. In fact SQL is also a very functional style language.

I see no problems with reading data from a database using a functional language.

Now modifying the database... that's a different story. I'll leave that for another day. :)

Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
2

Well, Lisp deals with lists, but the lists are heterogenous, and can well represent a tree. Other languages, like Haskell, give you structured types, named and unnamed, and - in contrast to lisp - allow for static type checking.

One thing that pure functional languages do not have is the notion of stateful variables that can be assigned. Some Lisp implementations provide such state - you get a setq opeator -, while Haskell doesn't. Reading and writing databases, however, is all about having state - and lots of it, that's what databases are for - and about reading from and writing into it. So, operating on a database is quite the opposite of using a functional language.

It does, however, make sense to create a database query language which expresses the DB operations in a non-imperative, but in a declarative, and hence in a functional way. That's how SQL makes sense, and that's also how the way LINQ is defined makes sense.

So, it makes sense to have a database language which is functional, but it's not because of the lists.

doppelfish
  • 963
  • 7
  • 18