How can I add type class constraints in type signature inside an instance when the type is a free variable in Haskell. For example:
{-# LANGUAGE InstanceSigs #-}
class Pair a where
pair :: a -> b -> (a, b)
instance Pair Int where
pair :: (Show a) => a -> b -> (a, b)
pair a b = (a, b)
works, 'a' is a bound type variable whereas:
{-# LANGUAGE InstanceSigs #-}
class Pair a where
pair :: a -> b -> (a, b)
instance Pair Int where
pair :: (Show b) => a -> b -> (a, b)
pair a b = (a, b)
gives this error:
source_file.hs:8:13:
No instance for (Show b)
Possible fix:
add (Show b) to the context of
the type signature for pair :: Int -> b -> (Int, b)
When checking that: forall a b. Show b => a -> b -> (a, b)
is more polymorphic than: forall b. Int -> b -> (Int, b)
When checking that instance signature for ‘pair’
is more general than its signature in the class
Instance sig: forall a b. Show b => a -> b -> (a, b)
Class sig: forall b. Int -> b -> (Int, b)
In the instance declaration for ‘Pair Int’