I'm currently working on method dispatch using pattern matching for julia, as a generalization of julia's
multiple dispatch.
Here's the
project page and the
discussion we had here on the list.
Since the first release, I've been working on a major overhaul of the basic pattern matching machinery, not through it yet :)
It should hopefully be more consistent, give more expressive power, and allow to generate better code.
My vision right now is:
* An underlying pattern matching framework that can
- parse and print patterns
- generate matching code from a pattern/a collection of patterns (to find the most specific match)
- unify patterns (form the pattern p that matches those values that match both p1 and p2)
- compare patterns to see whether one is more general than another
* A few useful macros to make the machinery available
- @pattern function
- @ifmatch let?
- @case (a la Haskell)?
- others?
A few planned features that are not on the project page yet:
* Unification in pattern expressions: the pattern
p~q matches
x if both patterns
p and
q do
* Matching on circularly linked data structures:
{1,x} matches any 2-length vector with first element 1,
x~{1,x} matches only such vectors where the second element refers to the vector itself.
* Compatibility with
EGAL (see also this
discussion) which will hopefully make its way into julia eventually.
* Guard conditions in the form of e g boolean expressions.
Please note one major difference from Haskell: dispatch will not choose the first matching pattern, but the most specific one (just as with multiple dispatch)
I don't have any experience with Haskell (just read up a bit on its pattern matching) or much experience with functional programming in general. Any feedback on my ideas is appreciated. (I also want to thank everyone who gave feedback the last round!)
/ Toivo