I am doing 20 intermediate Haskell exercises.
After finishing first 2 exercise there is this strange thing.
I would like to know what is ((->) t)
?
-- Exercise 3
-- Relative Difficulty: 5
instance Fluffy ((->) t) where
furry = error "todo"
Thanks! :-)
What's a typeclass in Haskell? A typeclass defines a set of methods that is shared across multiple types. For a type to belong to a typeclass, it needs to implement the methods of that typeclass. These implementations are ad-hoc: methods can have different implementations for different types.
From HaskellWiki. A type signature is a line like. inc :: Num a => a -> a. that tells, what is the type of a variable. In the example inc is the variable, Num a => is the context and a -> a is its type, namely a function type with the kind * -> * .
The ++ operator is the list concatenation operator which takes two lists as operands and "combines" them into a single list.
(->)
is the type constructor for functions which has kind * -> * -> *
so it requires two type parameters - the input and result type of the function. ((->) t
is a partial application of this constructor so it is functions with an argument type of t
i.e. (t -> a) for some type a
.
If you substitute that into the type of the furry
function you get:
furry :: (a -> b) -> (t -> a) -> (t -> b)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With