News for hackers. Stuff that matters.
Re:Near Future of Programming Languages [pdf] by tom_mellior on Monday October 30, 2017 @06:17PM (#15589461)
> For example, functions that return a different type depending on the values passed in are a useful pattern, but not allowed in staticly typed languages, except those with dependent types (Idris) or runtime downcasting (Go). There's always a way to acheive the same thing, but usually at the cost of safety or much more verbosity.

Look at this verbose OCaml:

    type my_return_type = AFloat of float | AnInt of int | AString of string;;

    let my_fun n =
        if n < 0 then AString "negative"
        else if n == 0 then AFloat 0.0
        else AnInt n

    # my_fun (-4);;
    - : my_return_type = AString "negative"
    # my_fun 0;;
    - : my_return_type = AFloat 0.
    # my_fun 42;;
    - : my_return_type = AnInt 42
(But yes, to use these values you have to do pattern matching, and if you're in a FUD mood, that is "runtime downcasting" and incurs a "cost of safety".)
Re:Near Future of Programming Languages [pdf] by smaddox on Tuesday October 31, 2017 @09:57AM (#15593237)
Yes, you can always generate a new union type for your return type and then pattern match on it. That is certainely better than C where you must use unsafe tagged unions or void pointers. It is more verbose than in dynamic duck-typed languages, though I'll give you that it's quite compact in OCaml.

In a dependently typed language, you could reduce verbosity at the use site as well as avoid the extra runtime branch.

Re:Near Future of Programming Languages [pdf] by tom_mellior on Tuesday October 31, 2017 @10:12AM (#15593340)
So how exactly would you write the above five lines of OCaml in fewer than five lines in Idris?
Re:Near Future of Programming Languages [pdf] by smaddox on Tuesday October 31, 2017 @03:02PM (#15595676)
The verbosity is not in the function definition, its in the match expression needed at _every single call site_. In Idris, the definition would be similar length or longer, but call sites would not need a match expression.