Let's say I have the following code (text in <>
is a shorthand, not actually part of the code):
data A = <something>
defaultA :: A
defaultA = <Really complicated expression of type A>
Now I want to have a function pattern match on defaultA
, like this:
f defaultA = <case 1>
f _ = <case 2>
However, defaultA
in the first line becomes a new variable, not a condition that means the parameter will equal defaultA
. The best way I know to achieve something like what I want is:
f x | x == defaultA = <case 1>
f _ = <case 2>
Does anyone know a better way?