News for hackers. Stuff that matters.
Re:“No, we’re telling everyone we are using Java” by vram22 on Saturday March 09, 2019 @03:00PM (#19348135)
How are F#'s and OCaml's implementation of it, in your opinion?
Re:“No, we’re telling everyone we are using Java” by macintux on Saturday March 09, 2019 @03:15PM (#19348215)
I’ve not tried either, although in my limited exposure to SML it seemed fine.

The other related feature whose lack I regularly lament in most languages is multiple function heads, which apparently is rarely used in the ML family tree, bafflingly.

Re:“No, we’re telling everyone we are using Java” by sgrove on Saturday March 09, 2019 @04:14PM (#19348525)
I haven't heard the term "multiple function heads" - is it similar to Haskell's way of defining functions? e.g.

    fib 0 = 0
    fib 1 = 1
    fib n = fib (n-1) + fib (n-2)
Re:“No, we’re telling everyone we are using Java” by yosh on Saturday March 09, 2019 @04:22PM (#19348561)
Yeah, this is Erlang:

    fib(0) -> 0;
    fib(1) -> 1;
    fib(N) -> fib(N-1) + fib(N-2).
Re:“No, we’re telling everyone we are using Java” by rad_gruchalski on Saturday March 09, 2019 @05:22PM (#19348889)
But these are all compiled into, essentially, a giant case statement. It’s a syntactic sugar. Your last line is missing a dot at the end.
Re:“No, we’re telling everyone we are using Java” by macintux on Saturday March 09, 2019 @06:38PM (#19349263)
Concise code is its own reward. Yes, it's syntactic sugar, but there's a reason syntactic sugar is valuable.

Even if performance is the same, you wouldn't prefer this Javaesque code:

    Int.from(8).multiply(5)
You'd use `8 x 5` were it available.

Several discrete function heads are easier to mentally parse than a long case statement because you know without a shadow of a doubt that there's no code in the function above or below the case statement, and you always have all relevant bindings directly adjacent to their usage.

Consider this Erlang code:

    f(X, Y) ->
       case X of
          {1, 2} ->
              low;
          {2, 4} ->
              high;
          {3, 6} ->
              Y
       end
    end.
When you get to the 3rd case statement and `Y` appears, it's jarring because it was declared several lines removed.

Instead, this code makes it explicit for each function clause that we don't care about the 2nd argument, and when we do care, it's immediately obvious where it came from.

    f({1, 2}, _) ->
       low;
    f({2, 4}, _) ->
       high;
    f({3, 6}, Y) ->
       Y.
Re:“No, we’re telling everyone we are using Java” by rad_gruchalski on Sunday March 10, 2019 @01:24PM (#19353008)
Yes, I agree with your point, I've written plenty of Erlang.
Re:“No, we’re telling everyone we are using Java” by macintux on Saturday March 09, 2019 @04:18PM (#19348539)
Exactly. I don’t know what the typical industry term for it might be.
Re:“No, we’re telling everyone we are using Java” by mercer on Sunday March 10, 2019 @01:38PM (#19353093)
Multiple Dispatch / Multimethods (I think?)
Re:“No, we’re telling everyone we are using Java” by macintux on Monday March 11, 2019 @12:24AM (#19356654)
Interesting, it appears that multiple dispatch is accurate. Thanks.
Re:“No, we’re telling everyone we are using Java” by mgradowski on Saturday March 09, 2019 @04:32PM (#19348620)
Pattern matching!
Re:“No, we’re telling everyone we are using Java” by macintux on Saturday March 09, 2019 @04:43PM (#19348687)
No, it relies on that, but the creation of multiple function clauses via different matched heads itself isn't simply pattern matching.