Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: cb0ee32425
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 28 lines (25 sloc) 0.757 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
type Pair = {
    left
    right
    extract
}
method tryMatch(o) {
    match(o)
        case { p : Pair(1, 2) -> print "The pair 1 and 2" }
        case { p : Pair(a : 5, b) -> print "Pair starting 5! ({a},{b})" }
        case { p : Pair(a : Pair, b : Pair(c : 3, d)) ->
            print "Pair of pairs, second starting 3. {a} {b} {c} {d}" }
        case { p : Pair(a, b) -> print "({a}, {b}) from {p}" }
        case { p : Pair -> print "PAIR ({p.left}, {p.right})" }
}

class aPair.new(l, r) {
    def left = l
    def right = r
    def extract = [l, r]
    def asString = "aPair.new({l}, {r})"
}

tryMatch(aPair.new(1, 2))
tryMatch(aPair.new(3,4))
tryMatch(aPair.new(5,6))
tryMatch(aPair.new(7,8))
tryMatch(aPair.new(aPair.new(1, 2), aPair.new(3, 4)))
Something went wrong with that request. Please try again.