I would ideally like to write something like this:
myValue1 = 1 :: Int myValue2 = 2 :: Int myFunc :: Int -> Bool myFunc myValue1 = True myFunc myValue2 = False
Calling myFunc myValue2 returns True – not what I intend. I know why this happens, but is there a way to express this in Haskell without resorting to C-style #define statements?
Well, Haskell doesn’t unify names like this. Those new ‘myValue1’ and ‘2’ identifiers are new variables you’re binding.
The most Haskelly way is to use strong types and pattern matching:
Giving you a static guarantee only “1” or “2” can be passed to myFunc, proper symbolic matching and you even retain conversion to integers by deriving Enum.