I'm currently learning Haskell from the ever awesome Haskell from first principles, and while trying to check the functor instances for each datatype using QuickCheck, I've stumbled against a mayor problem creating a Function
instance for my Four
datatype:
data Four' a b = Four' a a a b deriving (Eq,Show)
instance Function (Four' a b) where
function = let
injection :: (Function a, Function b) => (Four' a b) -> (a,a,a,b)
injection (Four' x1 x2 x3 z1) = (x1,x2,x3,z1)
surjection :: (Function a, Function b) => (a,a,a,b) -> (Four' a b)
surjection (x1,x2,x3,z1) = (Four' x1 x2 x3 z1)
in functionMap injection surjection
which throws the following error:
Error: • No instance for (Function a) arising from a use of ‘functionMap’
Possible fix:
add (Function a) to the context of
the type signature for:
function :: forall b1. (Four' a b -> b1) -> Four' a b :-> b1
or the instance declaration
• In the expression: functionMap injection surjection
Also, what is exactly the difference between trying to create a Function
instance and an Arbitrary
instance if they both generate functions?