[<<][softarch][>>][..]
Wed Jul 29 22:39:04 EDT 2020

Pattern matching

Lua doesn't have pattern matching.  However, it is possible to replace
pattern matchinging with generalized fold, where each alternative of
the sum type corresponds to a function.

Does that bring any notational convenience?

It would if every alternative is named.  So represent a match as a
dictionary of case clauses, represented as n-ary functions, each named
after the constructor.

So for a cons list this would be:

{
    nil  = function() ... end
    cons = function(car, cdr) ... end
}




[Reply][About]
[<<][softarch][>>][..]