I haven't heard of behavioral typing before. What would be an example (or pseudo-example) of this?
I haven't heard of behavioral typing before. What would be an example (or pseudo-example) of this?
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[0]: https://dzone.com/articles/duck-typing-scala-structural
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.