UFCS idea

Timon Gehr timon.gehr at gmx.ch
Wed Jun 8 17:10:48 PDT 2011


bearophile wrote:
> Andrej Mitrovic:
>
>> Keep the language simple, why the verbosity with special symbols?
>> Leave that to Perl 7 fans.
>
> My post was referring about two or three symbols. Regarding two of them, the $
and . operators used in Haskell, they may look a bit weird for the first hour your
use Haskell, > but after that you learn to appreciate them, and use them all the
time, because they allow you to write very clean code. Haskell code is not easy to
write for newbies, but
> it's easy enough to read. "Advanced" Haskell code uses several funny operators
(like &&&, etc), but the basic ones like ++ and $ have a very simple semantics and
you use them
> very often. So while Haskell is not an "easy" language, its code is more
readable and quite more clean than Perl code. In Perl you use all kind of side
effects, invisible
> variables, global variables, this doesn't happen in Haskell. So you can't
compare the two languages.
>
> In the end an operator like $ is just syntax sugar, so it's not so important.
>
> The third symbol I was talking about was the @ used to denote reference/pointer
types that can't be null (and ? used for the normal nullable ones). This is not
just syntax
> sugar, this needs a change to the type system too. And I think it's a change
important enough to deserve a special symbol in the language. Recently Andrei has
said something
> is moving about this whole topic, so we'll see.
>
> So I agree it's generally better to avoid special symbols, but there are
situations where they are acceptable, if their semantics is "natural" (like coming
from mathematics), > or if their usage is very common (like the $ . ++ in
Haskell), or if they are important enough (like a symbol used to denote
nullable/nonnullable reference type).
>
> Bye,
> bearophile

I'm very curious how you wold fit the $ operator into D. Afaik $ in haskell is
just an infix operator for (partial) function application at a lower precedence? D
does not have built in partial function application since all arguments are always
passed in tuples so you'd have a hard time to make

take 10 $ stride 2 $ cycle [1,2,3];

work in D.


Also, don't we have non-nullable references in the language already?:

int foo(ref int x){ // non nullable int reference!


Timon


More information about the Digitalmars-d mailing list