haskell - Difference in <$> and fmap -
i have line of code:
(++) <$> "hallo" <*> "du"
which outputs just "hallodu"
in "learn haskell great good" learned <$>
, fmap
same , indeed ghci outputs same type signature me. nevertheless, when write:
fmap (++) "hallo" <*> "du"
where difference?
yes <$>
, fmap
same thing using them in different expressions.
(++) <$> "hallo" <*> "du"
is equivalent to:
(++) `fmap` "hallo" <*> "du"
moving fmap
in infix position yields:
fmap (++) (just "hallo") <*> "du"
this due operator precedence , why <$>
more readable of time.
note in expression:
fmap (++) "hallo" <*> "du"
you passing 3
arguments fmap
((++)
, just
, "hallo"
), type doesn't match <*>
wants.
you want pass 2 arguments: (++)
, just "hallo"
.
Comments
Post a Comment