r/programming • • Mar 20 '14

Facebook introduces Hack: a new programming language for HHVM

https://code.facebook.com/posts/264544830379293/hack-a-new-programming-language-for-hhvm/
802 Upvotes

526 comments sorted by

View all comments

Show parent comments

5

u/pipocaQuemada Mar 20 '14

Why are types specified with the same syntax other languages use for extension?

What languages other than C# use ':' for inheritance? Also, ':' or '::' has been used in dozens of languages for type ascription dating back to the 70's. It's not a new syntactic invention by any means. Check out e.g. SML, OCaml, Haskell, Scala, F#, Clean, Miranda, etc.

The lambda syntax. Come on. FB, you invented a totally unfamiliar syntax for this, and it's totally verbose. I have to specify a method name, and then the method signature, and then the return type for the method signature, and then what the heck is ==>? The "identity greater than" operator? Is this yielding a value!? What is it!?

I assume you mean the snippet

function foo(): (function(string): string) {
  $x = 'bar';
  return $y ==> $x . $y;
}

I don't really know Hack, but it looks like it's the equivalent of the C#

Function<String, String> Foo() {
  String x = "bar";
  return (y => x + y); 
}

That is to say, you neither need to specif a method name nor a method signature, and ==> is the actual syntax for the lambda. It's not really that strange, especially because a number of languages use => for lambdas. Since it's a first class value, you can return it from a method, and if you want to give it a type, the type is "function(string): string".

1

u/[deleted] Mar 20 '14

I wondered if the type following the signature was a functional programming thing. Seeing as FB works with OCaml, I shouldn't be surprised.

Yes, I was (unintentionally) referring to the entire closure. I thought that was their solution for lambdas. /u/Nomikos pointed this out.

1

u/bstamour Mar 21 '14

C++ also uses : for inheritance. Probably where C# got it from.