Hacker News new | past | comments | ask | show | jobs | submit login

What language that has static types doesn't have the func, params, and return type in one line?



Some HM language can infer types at the toplevel so you may not have an explicit signature at all, although that's generally frowned upon:

    add1 = map (+1)
OTOH they also split the signature and function "header" so that you don't need to remove the "noise" to get the bare signature e.g.

    add1 :: (Num a) => [a] -> [a]
    add1 = map (+1)


C++ ends up with three forms (of course it does):

Normal C style declaration

    int foo() { return 2; }
Trailing return type. Useful when the return type depends on the parameter types, or is inside the namespace of the function

    auto foo() -> int { return 2; }
Automated type deduction. Increasingly the choice when possible

    auto foo() { return 2; }


K&R C had implied type of 'int' for both arguments and return value, and didn't list the types of arguments on the line specifying function name, argument names and return type:

  int foo(x,y)
  {
     return baz(x,y);
  }

  bar(x,y,z)
  short x;
  int z;
  {
     return x+y+z;
  }

  baz(x,y,z)
  {
     return 42;
  }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: