I am a beginner at Haskell and programming. I am learning how to write functions based on type declarations.How to write function which types are declared in brackets like (a -> b) -> b.
When I tried this:
z :: (Integer -> Integer) -> Integer
z x y = x + y
I got an error like this:
• Couldn't match expected type ‘Integer’
with actual type ‘(Integer -> Integer) -> Integer -> Integer’
• The equation(s) for ‘z’ have two arguments,
but its type ‘(Integer -> Integer) -> Integer’ has only one
If I give only one parameter assigned to the integer, it does type check,
z f = 9
but no idea how to use that function as it show an error when i type z 9:
• No instance for (Num (Integer -> Integer))
arising from the literal ‘5’
(maybe you haven't applied a function to enough arguments?)
• In the first argument of ‘z’, namely ‘5’
In the expression: z 5
In an equation for ‘it’: it = z 5
How to write proper functions for such type declarations and how do they work?