Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Language Syntax

Name: Anonymous 2012-01-31 16:18

So, /prog... which is the superior syntax for a statically typed language? Do you have a cleaner syntax I did not show? If so, ENLIGHTEN ME!



def fib(a: int): int
  if a < 2
    a
  else
    fib(a-1) + fib(a-2)
  end
end

(define (fib:int a:int)
  (if (< a 2)
    a
    (+ (fib (- a 1)) (fib (- a 2)))))

def fib(a int) int:
    if a < 2:
        return a
    else:
        return fib(a-1) + fib(a-2)

fib :: int -> int
fib a = if a < 2 then a
        else fib (a - 1) + fib (a - 2)

fib: method(a int,
  if(a <(2), a)
  else(fib(a -(1)) +(fib(a-(2)))))

procedure fib(a: int): int;
begin
  if a < 2 then
    return a;
  else
    return fib(a-1) + fib(a-2);
  end;
end;

int fib(int a)
{
    if (a < 2)
        return a;
    else
        return fib(a-1) + fib(a-2);
}

func fib (a int) int {
    if a < 2 {
        return a;
    } else {
        return fib(a-1) + fib(a-2);
    }
}

Name: Anonymous 2012-01-31 22:08

>>16
Yes, it's probably the same in F# too. (It's great because the plebs can't tell it's statically typed.)

>>19
Satisfying types for the whole program really isn't that hard. If you know how to write in the various MLs, you will use the B&D nature of type system to enforce the correctness of your code in many areas. While satisfying types doesn't inherently make your program correct, being unable to satisfy your types does mean you can't write a correct program.

So what you said boils down to "writing larger programs is harder." The H-M type system is there to help you with that problem. Ignorance is not the solution.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List