Closed mlhaufe closed 1 year ago
Data
? Does this open the possibility of predicate/tag checking?
otherwise
pattern. Can _
be used?===
against the membersconst traitName = Trait(DataDecl, {
VariantName: (self, ...args) => {...},
VariantName: [
[[pattern1, pattern2, ...patternN], (self, v2, ...vN) => {...}]
]
})
// Literals
1
false
'foo'
// wildcard
_
// variant instances
Nil
Cons(1, Nil)
Cons(pattern1, pattern2)
Cons(1, Cons(pattern, Nil)
// structural
{left: 3, right: Nil }
{left: pattern1, right: pattern2 }
Problem 1
Given the following definition and associated expression:
How can
e
be simplified toVar('x')
?Currently here is the idiomatic approach:
With pattern matching (hypothetical syntax) the following may be possible:
Problem 2
For the Fibonacci function, here is the current approach:
If literals are allowed for Trait and
all
was replaced by_
:References
Work items: