module Data where
data Cons a = Con (a -> Bool)
deriving (Show)
twoCons :: Cons a -> Cons a -> Cons a
twoCons (Con a) (Con b) = Con (twoCons' a b)
twoCons' :: (a -> Bool) -> (a -> Bool) -> (a -> Bool)
twoCons' c1 c2 x = (c1 x) && (c2 x)
This code doesn’t work, with or without deriving (Show).
It’s supposed to combine two tests/constraints and return a function wrapped by the third Con.
The constraints might be (>1) and (<10), the outcome should be an combination of the two constraints, the type of constraint can be anything.
The problem is that there is no reasonable way to write an instance of
ShowforCons(try it yourself!)If you remove the
deriving (Show)clause your code works perfectly.