[Haskell-cafe] funct.prog. vs logic prog., practical Haskell

Peter Verswyvelen bugfact at gmail.com
Tue Aug 4 07:26:07 EDT 2009


On Sun, Aug 2, 2009 at 12:25 PM, Petr Pudlak <deb at pudlak.name> wrote:

> I'd like to convince people at our university to pay more attention to
> functional languages, especially Haskell. Their arguments were that
>
>    (1) Functional programming is more academic than practical.
>    (2) They are using logic programming already (Prolog); why is Haskell
>        better than Prolog (or generally a functional language better than a
>        logic programming language)?


Regarding (1), today it's common to do functional programming in
"industrially accepted" languages, at least if you want to be productive :)

Take for example the following C# code, taken from production code:

var graphs = selection.SelectMany(
        e => e.SelfAndIntraGraphAncestors()
                 .OfType<IGraphContainer>()
                 .Take(1)
                 .SelectMany(gc => gc.ChildGraphs));

Each of these C# methods work on lazy streams, so this even lazy functional
programming in a sense :) (albeit with potential side effects)

I could write this in imperative style, something like this (but it's not
the same, the code below is strict, a lazy version would be much longer,
unless I cheat and use C#'s yield statement)

var graphContainers = new List<IGraphContainer>();
foreach( var entity in selection )
{
   foreach( var ancestor in entity.SelfAndIntraGraphAncestors() )
   {
       var graphContainer = ancestor as IGraphContainer;
       if( graphContainer != null )
       {
           foreach( var childGraph in graphContainer.ChildGraphs )
           {
               graphContainers.Add(childGraph);
           }
           break;
       }
   }
}

Obviously the second one is much less declarative and more difficult to read
(and maintain).

So really, any good industrial programmer should master at least the basics
of functional programming. Haskell might be one of the most beautiful and
elegant languages to use for learning functional programming.

Also IMHO any experienced programmer should understand that although popular
imperative programming languages like C++, C#, Java, Python, etc are more
"powerful" than pure functional languages (in these sense that you can peek
and poke around without restrictions like a crazy chicken), in practice this
power is so difficult to control that it's a bit like giving everybody the
right to carry a gun in public so people would feel safer ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090804/89106798/attachment.html


More information about the Haskell-Cafe mailing list