# Haskell Applicative ## Metadata **Status**:: #x **Zettel**:: #zettel/fleeting **Created**:: [[2026-01-30]] **Parent**:: [[Haskell]] ## Synopsis Applicative allow apply a wrapped function to a wrapped value. `pure` wraps a value into the type that is an instance of Applicative. ```haskell pure 1 :: Maybe Int -- Just 1 pure 'z' :: [Char] -- "z" -- Wrapped as the return value of a function `a -> Int` pure 1 $ "any" -- 1 ``` ```mermaid flowchart LR I@{shape: text, label: "x"} -- pure --> x ``` `liftA2` applies an operator to the inner values when they are not empty. ```haskell liftA2 (+) (Just 2) (Just 3) -- Just 5 liftA2 (+) (Just 2) Nothing -- Nothing liftA2 (+) [1,2] [10,100] -- [11,101,12,102] -- Use `ZipList` for pairwise `liftA2` on lists. getZipList $ liftA2 (+) (ZipList [1, 2]) (ZipList [10, 100]) -- [11,102] ``` ```mermaid flowchart LR Op@{shape: text, label: "(+)"} --> x x --> y y -- liftA2 --> O["x + y"] ``` `<gt;` applies a normal function to the inner value ```haskell negate <gt; (Just 5) -- Just (-5) ``` ```mermaid flowchart LR Op@{shape: text, label: "negate"} --> x x -- "<gt;" --> O["negate x"] ``` `<*>` applies a wrapped function to a wrapped value ```haskell (Just negate) <*> (Just 10) -- Just (-10) ``` ```mermaid flowchart LR Op[negate] --> x x -- "<*>" --> O["negate x"] ``` Exchange between `LiftA2` and `<*>`: ```haskell (<*>) = liftA2 id liftA2 f x y = f <gt; x <*> y ``` `<gt;` is the infix alias of `fmap` and can be written as ```haskell f <gt; x = pure f <*> x (<gt;) = (<*>) . pure ```