Go rant

retard re at tard.com.invalid
Fri Dec 18 17:54:22 PST 2009


Fri, 18 Dec 2009 16:42:27 -0800, Walter Bright wrote:

> bearophile wrote:
>> Please ask if you have missed my two points, because they must be
>> understood if you want to design a modern language.
> 
> I believe I do get it. After all, look at D's support for functional
> programming (immutable and pure).
> 
> I wrote the post in reply to "Can you show one example that looks uglier
> in Scala, but looks decent in D or some other language?" Whatever the
> advantages of FP, and there are many, to keep trotting out the qsort
> example front and center is a huge mistake. The Haskell qsort example is
> horrible in that it purports to show how elegant and simple FP is, but
> instead shows a misguided and essentially useless implementation.
> 
> The Haskell qsort example is not only the VERY FIRST example given for
> the language on the INTRODUCTORY PAGE of the Haskell wiki, and is under
> the heading "What's good about functional programming?". There is no
> mention in the text of any of the egregious shortcomings of the example.
> 
> 
>> Note that for real sorting purposes you don't use that onliner, you use
>> some kind of system sort.
> 
> In other words, the #1 example of how great Haskell is sucks and is
> useless for real programming.
> 
> The Haskell folks really need to find a better canonical example.

Let's try some better examples then:

**) function composition [haskell]

(.)                     :: (b->c) -> (a->b) -> (a->c)
f . g                   = \ x -> f (g x)

(note how the syntax is readable unlike the ass-backwards function type 
syntax in C/D)


**) custom control structures [scala]

(new Object) synchronized {
  ...
}

1 to 42 foreach println

react {}, loop {}, receive {} etc. in actors lib


**) consistent return values from control constructs

a = if predicate then foo else bar

val a = if (predicate) foo else bar

b = case foo of
  A -> 1
  ...
  Z -> 27

val b = foo match {
  case A => 1
  ...
  case Z => 27


**) serious pattern matching [scala]

foo match {
  case Nil => println("Empty list, it seems")
  case 1 :: 2 :: _ => println("Got 1,2,… list")
  case 9 :: 8 :: 7 :: _ => println("Got 9,8,7,… list")
  case _ =>
}

**) lazy evaluation

myIf a b c = if a then b else c

def myIf[A <: C,B <: C,C](a: Boolean, b: => A, c: => B) = if (a) b else c



More information about the Digitalmars-d mailing list