data D = A Int Int | B Int Char
instance Show D where
show (A a b) = show b
show (B a b) = show b
hehe :: D -> String
hehe d = show u ++ show v
where (u, v) = show <$> case d of
A a b -> (a + 1, b)
B a b -> (a + 2, b)
The idea is that I want to apply a function over a tuple, but it does not type check because the second element of the tuple can either be an Int or a Char.
Here is the error message:
* Couldn't match expected type `Int' with actual type `Char'
* In the expression: b
In the expression: (a + 2, b)
In a case alternative: B a b -> (a + 2, b)
|
11 | B a b -> (a + 2, b)
|
I wonder if there is an elegant solution to solve this?