>>> 5 & (+1) & show "6"
>>> sqrt $ [1 / n^2 | n <- [1..1000]] & sum & (*6) 3.1406380562059946
type Api = NamedRoutes RootApi data RootApi mode = RootApi { subApi :: mode :- NamedRoutes SubApi , … } deriving Generic data SubApi mode = SubApi { endpoint :: mode :- Get '[JSON] Person , … } deriving Generic api :: Proxy API api = Proxy rootClient :: RootApi (AsClientT ClientM) rootClient = client api endpointClient :: ClientM Person endpointClient = client // subApi // endpoint
<*> monoidalFieldAla "extensions" (alaList' FSep MQuoted) oldExtensions ^^^ deprecatedSince [1,12] "Please use 'default-extensions' or 'other-extensions' fields."
>>> map (apply 2) [succ, recip, negate] [3.0,0.5,-2.0]In general you should prefer using an explicit lambda or operator section.
>>> map (\ f -> 2 |> f) [succ, recip, negate] [3.0,0.5,-2.0] >>> map (2 |>) [succ, recip, negate] [3.0,0.5,-2.0] >>> map (<| 2) [succ, recip, negate] [3.0,0.5,-2.0]
\ x -> apply x f == f x
>>> 3 !> succ !> recip !> negate -0.25The difference between this and (|>) is that this evaluates its argument before passing it to the function.
>>> undefined |> const True True >>> undefined !> const True *** Exception: Prelude.undefined ...
\ x -> (x !> f) == seq x (f x)
\ x -> (x !> f !> g) == let y = seq x (f x) in seq y (g y)
>>> map (apply' 2) [succ, recip, negate] [3.0,0.5,-2.0]The different between this and apply is that this evaluates its argument before passing it to the function.
>>> apply undefined (const True) True >>> apply' undefined (const True) *** Exception: Prelude.undefined ...In general you should prefer using an explicit lambda or operator section.
>>> map (\ f -> 2 !> f) [succ, recip, negate] [3.0,0.5,-2.0] >>> map (2 !>) [succ, recip, negate] [3.0,0.5,-2.0] >>> map (<! 2) [succ, recip, negate] [3.0,0.5,-2.0]
\ x -> apply' x f == seq x (f x)
mkElement "div" # set style [("color","#CCAABB")] # set draggable True # set children otherElements
grd # addColorStop(0, "#8ED6FF");This can be seen as equivalent of grd.addColorStop(0, "#8ED6FF").
>>> 255 .@hex "0x0000_0000_0000_00ff" >>> 0xf1 .@bin "0b1111_0001" >>> 2^12 .@dec "4096" >>> 4 * giga .@pos1 [32]
0x0 .@color (bits 31 24) 0b0000_0000_0000_0000_0000_0000_0000_0000_1111_1111_0000_0000_0000_0000_0000_0000 ^^^^ ^^^^
onApp = (&)
($) :: (a -> b) -> a -> b ($) f x = f xThis is id specialized from a -> a to (a -> b) -> (a -> b) which by the associativity of (->) is the same as (a -> b) -> a -> b. On the face of it, this may appear pointless! But it's actually one of the most useful and important operators in Haskell. The order of operations is very different between ($) and normal function application. Normal function application has precedence 10 - higher than any operator - and associates to the left. So these two definitions are equivalent:
expr = min 5 1 + 5 expr = ((min 5) 1) + 5($) has precedence 0 (the lowest) and associates to the right, so these are equivalent:
expr = min 5 $ 1 + 5 expr = (min 5) (1 + 5)
-- | Sum numbers in a string: strSum "100 5 -7" == 98 strSum :: String -> Int strSum s = sum (mapMaybe readMaybe (words s))we can deploy the function application operator:
-- | Sum numbers in a string: strSum "100 5 -7" == 98 strSum :: String -> Int strSum s = sum $ mapMaybe readMaybe $ words s($) is also used as a section (a partially applied operator), in order to indicate that we wish to apply some yet-unspecified function to a given value. For example, to apply the argument 5 to a list of functions:
applyFive :: [Int] applyFive = map ($ 5) [(+1), (2^)] >>> [6, 32]
fastMod :: Int -> Int -> Int fastMod (I# x) (I# m) = I# $ remInt# x m
f $ g $ h x = f (g (h x))It is also useful in higher-order situations, such as map ($ 0) xs, or zipWith ($) fs xs. Note that ($) is levity-polymorphic in its result type, so that foo $ True where foo :: Bool -> Int# is well-typed.