News for hackers. Stuff that matters.
Re:Programming Language Rankings: June 2016 by Xcelerate on Thursday July 21, 2016 @05:37AM (#12135754)
> In short: Julia may be the first language to pull off behavioral typing in a practically usable way.

I haven't heard of behavioral typing before. What would be an example (or pseudo-example) of this?

Re:Programming Language Rankings: June 2016 by jballanc on Thursday July 21, 2016 @11:12AM (#12137378)
Up until now it's been the realm of PL research. The Ptolemy language is one example I know of: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.86.... [PDF]

If you're familiar with duck typing, behavioral typing is (in essence) the reification of duck typing in a concrete type system. In other words, instead of specifying the type of your argument as "Array", you could specify "some type that is indexable, iterable, and can be appended to".

In Julia (mind you this was just the idea I saw being considered), today you would do:

    function foo(myarray::AbstractArray)
      ...
    end
but in the future you might be able to do something like:

    function foo(myarray::ANY{getindex(), setindex(), iterate(), append()})
      ...
    end
what's really neat, though, is combining this with type aliases, you could have:

    typealias Arraylike ANY{getindex(), setindex(), iterate(), append()}
    function foo(myarray::Arraylike)
      ...
    end
Re:Programming Language Rankings: June 2016 by SatvikBeri on Thursday July 21, 2016 @11:52AM (#12137647)
Unless I'm mistaken, this seems to already be available in Scala and is called "structural typing"[0]. Is there a substantial difference?

[0]: https://dzone.com/articles/duck-typing-scala-structural

Re:Programming Language Rankings: June 2016 by jballanc on Thursday July 21, 2016 @05:12PM (#12140118)
The difference between structural typing and behavioral typing is subtle. In Scala, you're essentially asking the type system to check for the presence of a member function on the object with a specific type signature. Since the function is contained within the object, you're still only typing based on the object's structure (hence: structural typing).

In Julia, objects are data-only and methods are defined at a module level. So, whereas Scala's structural typing need only introspect the object being passed as an argument, Julia's behavioral typing requires introspection of the entire dispatch tree. The benefit to behavior typing and Julia's multi-dispatch is that if you are missing one or two methods for some type in order to be able to use it in some function, you can always define the missing methods locally.

Re:Programming Language Rankings: June 2016 by SatvikBeri on Thursday July 21, 2016 @05:23PM (#12140182)
Great explanation, thank you.
Re:Programming Language Rankings: June 2016 by swift on Thursday July 21, 2016 @05:48PM (#12140341)
You could also view C++ templates as a kind of behavioral typing, although the experience of using them in that way is not very pleasant. Concepts should help clean that up when they finally arrive in the spec.