[Haskell-cafe] Re: Is Haskell a 5GL?

Ch. A. Herrmann herrmann at uni-passau.de
Thu Oct 5 04:48:33 EDT 2006


Henning Thielemann wrote:

> ...
>The notation
>   [f x | x <- xs]
> describes operations on list elements, and looks like the imperative
>  "forall x in xs do f x",
>  map f xs
> is a list transformation. The second one is more abstract, isn't it?
for that simple example yes, but what's about list comprehensions like:

sequence of parsers:
(p <+> q) r = [ (f (x,y), r2) | (x, r1) <- p r, (y, r2) <- q r1 ]

or triples:
[ (x,y,z) | x<-[1..n], let x2=x*x, y<-[1..x], let y2=y*y, let z=isq 
(x2,y2), x2+y2==z*z ]

or database queries:
[ (name,salary) | ((_,name),dateofbirth,((Just salary))) <- table, 
dateofbirth>1980 && salary>100000 ]

I just typed these examples but did not check them.

There are many other examples like n queens, functions on shaped 
matrices etc.


More information about the Haskell-Cafe mailing list