“Pattern-matching” types in Haskell

1

I want a function f that acts as an increment on Ints 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?

Share
Improve this question

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

flutter websocket connection issue