Example of broken code:
data Foo = Foo {
bar :: (Int -> Int)
}
baz = Foo { bar i = i*3 }
Why isn't this possible?
It's just a syntactic limitation - I suspect that if this feature has been considered, it would have been rejected because there are straightforward alternatives. Also, if it was supported, the next question would be why not pattern-matching with multiple clauses, and overall it would just make the language bigger for not all that much gain.
You can use baz = Foo { bar = \x -> x*3 }
instead for the specific case you've given, or define an auxiliary function.
This should work:
baz = Foo { bar = (\x -> x*3) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With