Answer the question
In order to leave comments, you need to log in
What is the type of the first (left) occurrence of the operator in the expression succ succ "abc"?
A couple of months ago, I quite successfully completed the first part of the "Functional Programming in Haskell" course from Stepik, recently took up the second part, and "broke" on the very first task:
The Data.Functor module defines the <$> operator , which is an infix analogue of the fmap function :
GHCi> :info <$> (<$>) :: Functor f => (a -> b) -> f a -> f b -- Defined in `Data.Functor' infixl 4 <$>
In the expression succ <$> "abc" this operator is of type (Char -> Char) -> [Char] -> [Char] . What is the type of the first (left) occurrence of this operator in the expression succ <$> succ <$> "abc" ?
Answer the question
In order to leave comments, you need to log in
Since the (<$>) operator is infixl, the original expression is equivalent to:
(succ <$> succ) <$> "abc".
Therefore (succ <$> succ) is of type (Char -> Char).
Hence the second and first succ functions in parentheses are of type (Char -> Char).
Hence the answer is: (Char -> Char) -> (Char -> Char) -> (Char -> Char).
Notice the following instance:
instance Functor ((->) r) where
fmap = (.)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question