where clause
bearophile
bearophileHUGS at lycos.com
Mon Mar 7 03:28:14 PST 2011
Russel Winder:
>I wonder if you may have misunderstood the reason for the where clause in functional languages such as Haskell and ML (usually OCaml). In these languages the body of a function must be a single value-returning expression. This means there has to be a separate clause for all the declarations of the single-assignment variables -- caveat the use of monads<
Right, but the point of my post was that a where statement is able to give some advantages to D too.
> What's wrong with:
>
> {
> auto sqr =3D function int ( int ) { return x * x ; } ;
> auto r =3D map ! ( sqr ) ( items ) ;
> }
>
> Seems idiomatic and straightforward with less noise?
Both my code and this code are kind of useless because their variables will not be accessible when the block ends. So my syntax is not good :-(
> so there are times when you do nest functions -- basically to make
> closures very analogously to the way you seem to have to in D.
Nesting functions is very useful. Python Zen is not a list of absolute laws :-)
> PS I have begun to dislike languages that use semi-colon as a statement
> terminator! (It took me 4 attempts to get my two line example to
> compile :-((
I like Python but I have found some Haskell code on web pages, that I copy and try to run. I am having many problems caused by tabs present in the original code that vanish in HTML and break haskell indentations, creating bugs. So be careful what you wish for.
>From the web interface your posts are often empty/invisible:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=131443
Bye,
bearophile
More information about the Digitalmars-d
mailing list