This helps here if you try to slightly ignore the detailed types and look at the big picture.
Think <$>and <*>as special versions $, which operate at a different level.
Applicative functors in general
- , AF,
x :: AF a
y :: AF b
z :: AF c
, " -", a, b c,
f :: a -> b -> c -> d
, d.
f <$> x <*> y <*> z :: AF d
"do" x, y, z f .
, f $ a $ b $ c.
, f <$> x <*> y <*> z
do
a <- x
b <- y
c <- z
return (f a b c)
, ( ). areq aopt AForm sub master ??. sub master - / . ?? - .
areq textField "Name" Nothing - , Text,
areq (jqueryDayField def) "Birthday" Nothing - , a Day,
Text.
data Person = Person Text Day Text Text Text
Person :: Text -> Day -> Text -> Text -> Text -> Person, ,
Person
<$> areq textField "Name" Nothing
<*> areq (jqueryDayField def
{ jdsChangeYear = True -- give a year dropdown
, jdsYearRange = "1900:-5" -- 1900 till five years ago
}) "Birthday" Nothing
<*> aopt textField "Favorite color" Nothing
<*> areq emailField "Email address" Nothing
<*> aopt urlField "Website" Nothing
, Person, Person.
,
do
name <- areq textField "Name" Nothing
day <- areq (jqueryDayField def
{ jdsChangeYear = True
, jdsYearRange = "1900:-5"
}) "Birthday" Nothing
color <- aopt textField "Favorite color" Nothing
email <- areq emailField "Email address" Nothing
website <- aopt urlField "Website" Nothing
return $ Person name day color email website
, , .
, <$> <*>?
, ,
pureFunction <$> af1 <*> af2 <*> af3 <*> af4 ....
<$> <*> . , , pureFunction . . ( .) :
<$> :: Functor f => (a -> b) -> f a -> f b
<*> :: Applicative f => f (a -> b) -> f a -> f b
, <$> , <*>, , , <$> . , (++) "Hello", :: String -> String,
getLine :: IO String -- produces a String
(++) <$> getLine :: IO (String -> String) -- produces an appender
(++) <$> getLine <*> getLine :: IO String -- produces a combined String
areq textField "Name" Nothing
:: AForm sub master Text
Person :: Text -> Day -> Text -> Text -> Text -> Person, name::Text, Person name Day -> Text -> Text -> Text -> Person
Person <$> areq textField "Name" Nothing
:: AForm sub master (Day -> Text -> Text -> Text -> Person)
<*> -, Day, -, (Text -> Text -> Text -> Person), , -, Person. ( , -> , <$> <*> - , , $).