Commit 8b823f27 authored by Gabriel Lebec's avatar Gabriel Lebec 🥃 Committed by Ben Gamari

docs(Data.Function): fix and augment `on` annotation

parent a5bfb7e1
...@@ -50,18 +50,21 @@ infixl 1 & ...@@ -50,18 +50,21 @@ infixl 1 &
fix :: (a -> a) -> a fix :: (a -> a) -> a
fix f = let x = f x in x fix f = let x = f x in x
-- | @((==) \`on\` f) x y = f x == f y@ -- | @'on' b u x y@ runs the binary function `b` /on/ the results of applying unary function `u` to two arguments `x` and `y`. From the opposite perspective, it transforms two inputs and combines the outputs.
--
-- @((+) \``on`\` f) x y = f x + f y@
-- --
-- Typical usage: @'Data.List.sortBy' ('compare' \`on\` 'fst')@. -- Typical usage: @'Data.List.sortBy' ('compare' \`on\` 'fst')@.
--
-- Algebraic properties: -- Algebraic properties:
-- --
-- * @(*) \`on\` 'id' = (*)@ (if @(*) ∉ {⊥, 'const' ⊥}@) -- * @(*) \`on\` 'id' = (*) -- (if (*) ∉ {⊥, 'const' ⊥})@
-- --
-- * @((*) \`on\` f) \`on\` g = (*) \`on\` (f . g)@ -- * @((*) \`on\` f) \`on\` g = (*) \`on\` (f . g)@
-- --
-- * @'flip' on f . 'flip' on g = 'flip' on (g . f)@ -- * @'flip' on f . 'flip' on g = 'flip' on (g . f)@
on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
(.*.) `on` f = \x y -> f x .*. f y
-- Proofs (so that I don't have to edit the test-suite): -- Proofs (so that I don't have to edit the test-suite):
-- (*) `on` id -- (*) `on` id
...@@ -102,9 +105,6 @@ fix f = let x = f x in x ...@@ -102,9 +105,6 @@ fix f = let x = f x in x
-- = -- =
-- flip on (g . f) -- flip on (g . f)
on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
(.*.) `on` f = \x y -> f x .*. f y
-- | '&' is a reverse application operator. This provides notational -- | '&' is a reverse application operator. This provides notational
-- convenience. Its precedence is one higher than that of the forward -- convenience. Its precedence is one higher than that of the forward
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment