Login | Register
dobesv 8 Jul 2012
I recently bumped into this rather interesting language called Felix.
The way they handle pattern matching is quite interesting.
Basically there's a specific type of type called a "union". The union represents a type that has alternative contents, as distringuished from a normal class that has all fields available at once.
Unions work hand-in-hand with pattern matching - you use the match operation on a union type to operate on the fields that are present for the variation of the union you are dealing with.
Anyway, I thought it might serve as useful fodder when thinking about this matter for Fantom's own design. It doesn't allow you to match against arbitrary classes, but I think if put to good use it can hit the most popular cases.
You can read the little bit of documentation about it here:
Jens 12 Jul 2012
This seems to be the usual union type from lambda calculus, known as algebraic datatypes (ADT) in ML and Haskell.
Scala has gone another way and do patterns matching on case classes, which is like normal classes.
I think pattern matching is a very neat way of writing logic, which could be next thing to steal from functional programming, after lambda-expressions.
Login or Register to Reply
Back | All Topics
Collapse All Expand All