Looking at reader or environment applicativefrom Brent Yorgey UPenn 2013 Lecture :
reader or environment applicative
instance Functor ((->) e) where fmap = (.) instance Applicative ((->) e) where pure = const f <*> x = \e -> (f e) (x e)
I am trying to get an intuition for an applicative instance.
Given:
(<*>) :: Applicative f => f (a -> b) -> f a -> f b
then how does it \e -> (f e) (x e)lead to type f b?
\e -> (f e) (x e)
f b
If we substitute ((->) e)for f(remembering that this is a function with eas the type of the argument), we get:
((->) e)
f
e
(<*>) :: f (a -> b) -> f a -> f b (<*>) :: ((->) e) (a -> b) -> ((->) e) a -> ((->) e) b -- Replace f with ((->) e) (<*>) :: (e -> (a -> b)) -> (e -> a) -> (e -> b) -- Apply ((->) e) (<*>) :: (e -> a -> b) -> (e -> a) -> e -> b -- Remove unneeded parentheses
It is important to remember what ((->) e) acoincides with e -> a. Notation may look a little misleading at the beginning.
((->) e) a
e -> a
The only implementation for this type is the one you provided in your question. This definition can also be written as:
f <*> x = \e -> f e (x e)
or using prefix notation:
(<*>) f x e = f e (x e)
S combinator. ( , .)
:
zipping. (f a), e. , , , e: e . :
a
f 0, f 1, f 2 .. 0, a 1, a 2 .. (f 0, a 0), (f 1, 1), (f 2, a 2) ..
fi ai, (f 0 a 0), (f 1 a 1), (f 2 a 2) .. , f a, ( "" ), , . , S-.
fi
ai
Source: https://habr.com/ru/post/1569584/More articles:warning: format '% d ожидает аргумент типа' int, но аргумент 2 имеет тип 'long int [-Wformat =] - cSpring security: java.sql.SQLException: индекс столбца выходит за пределы диапазона, 3> 2 - javaFirefox disables webcam connection for self-signed certificate - firefoxВычисление и улучшение сложности времени и памяти (Java) - javaHow to get chrome.runtime.on Installed to run when using Require.JS in the Chrome extension - javascriptFailed to create receiver instance com.parse.GcmBroadcastReceiver - javaCutting mask for SVG - css3Angular. Ограничить: "А". Пропустить объект - angularjsNode JS является асинхронным Чтение/Запись безопасным? - node.jsПопытка заменить строку "на лету", лучший способ? - javascriptAll Articles