“Pattern-matching” types in Haskell
1
I want a function f
that acts as an increment on Int
s and as an identity on all the other types. I tried to enable the TypeApplications
extension and do this the most straight-forward way possible:
f :: forall a. a -> a
f @Int x = x + 1
f @_ x = x
But the extension does not enable such patterns:
<interactive>:6:1: error: Parse error in pattern: f @Int
Is there pattern-matching for types (or a similar mechanism) in Haskell?
haskell types functional-programming
Add a comment
|