Neden <$>
doğru değil,(f . g) <$> x
eşdeğerdir?
(denklik Bu tür düz $
ile a popular idiom geçerlidir, ancak şu anda $
sağ ilişkisel değildir!)
<*>
<$>
aynı çağrışımsallık ve önceliğe sahiptir, ancak farklı davranış!
Örnek: <$>
tanımına itibaren
Prelude Control.Applicative> (show . show) <$> Just 3
Just "\"3\""
Prelude Control.Applicative> show <$> show <$> Just 3
Just "\"3\""
Prelude Control.Applicative> pure show <*> pure show <*> Just 3
<interactive>:12:6:
Couldn't match type `[Char]' with `a0 -> b0'
Expected type: (a1 -> String) -> a0 -> b0
Actual type: (a1 -> String) -> String
In the first argument of `pure', namely `show'
In the first argument of `(<*>)', namely `pure show'
In the first argument of `(<*>)', namely `pure show <*> pure show'
Prelude Control.Applicative>
Prelude Control.Applicative> :i (<$>)
(<$>) :: Functor f => (a -> b) -> f a -> f b
-- Defined in `Data.Functor'
infixl 4 <$>
Prelude Control.Applicative> :i (<*>)
class Functor f => Applicative f where
...
(<*>) :: f (a -> b) -> f a -> f b
...
-- Defined in `Control.Applicative'
infixl 4 <*>
Prelude Control.Applicative>
, ben de show <$> show <$> Just 3
başarısız beklenebilir.
Bu akıllı gözlem için teşekkürler! –
Eh, _you_ gözlemledi, değil mi? Sadece ayrıştırdım ve yazdım ... – leftaroundabout
Diğer Functor örneğini dikkate almayı kastettim. Belki de, "gözlem" bunun için iyi bir kelime değildir. –