The reason why they don't do that is that you can reference variable names:
foo = 1
switch bar {
// Equals the value of (existing) variable foo
case foo: return 0
// Catch-all, binds `foo` to whatever is in `bar`
case let foo: return foo + 1
}
(My syntax might be off, I've never written Swift)
To do this in Haskell, you'd have to write something like:
foo = 1
case bar of
foo' | foo' == foo -> 0
foo -> foo + 1
Because you're only able to pattern-match against literal objects (constructors or numeric/string literals).
This might be different in some other ML-like languages, or there could be GHC extensions for this, of course.
To do this in Haskell, you'd have to write something like:
Because you're only able to pattern-match against literal objects (constructors or numeric/string literals).This might be different in some other ML-like languages, or there could be GHC extensions for this, of course.