Paste: match in clay

Author: j
Mode: text
Date: Fri, 6 Aug 2010 00:49:55
Plain Text |
procedure match;
[T] overload match(x:T, static T, fn, ...etc) = ...fn(x);
[T, U | T != U] overload match(x:T, static U, fn, ...etc) = ...match(x, ...etc);

variant Foo = Int | Float;

foo(x) {
    match(*x,
        Int, lambda(x) { println("I saw an Int ", x); },
        Float, lambda(x) { println("I saw a Float ", x); }
    );
}

New Annotation

Summary:
Author:
Mode:
Body: