git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Make 'compare on' example idiomatic
commit96b7f82659f74cf1c9ccb1406dcc6fd3cf191ddd authorPhil Freeman <paf31@cantab.net> dateMon 2 Mar 2015, 16:59 (12 years ago) parentfe525f9
2 files changed+8−10
prelude/README.md+4−5 prelude/prelude.purs+4−5
prelude/README.md+4−5
@@ -252,7 +252,7 @@ types use the type constructor `f` to represent some computational context.
252252(<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
253253```
254254
255−`(<#>)` is `(<$>)` with its arguments flipped. For example:
255+`(<#>)` is `(<$>)` with its arguments reversed. For example:
256256
257257```purescript
258258[1, 2, 3] <#> \n -> n * n
@@ -880,14 +880,13 @@ on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
880880
881881The `on` function is used to change the domain of a binary operator.
882882
883−For example, given a function `height :: Person -> Number`, we can create a function which compares two people by height:
883+For example, we can create a function which compares two records based on the values of their `x` properties:
884884
885885```purescript
886−taller :: Person -> Person -> Boolean
887−taller = (>) `on` height
886+compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
887+compareX = compare `on` _.x
888888```
889889
890−
891890#### `Fn0`
892891
893892``` purescript
prelude/prelude.purs+4−5
@@ -234,7 +234,7 @@ module Prelude
234234 class Functor f where
235235 (<$>) :: forall a b. (a -> b) -> f a -> f b
236236
237− -- | `(<#>)` is `(<$>)` with its arguments flipped. For example:
237+ -- | `(<#>)` is `(<$>)` with its arguments reversed. For example:
238238 -- |
239239 -- | ```purescript
240240 -- | [1, 2, 3] <#> \n -> n * n
@@ -868,13 +868,12 @@ module Data.Function where
868868
869869 -- | The `on` function is used to change the domain of a binary operator.
870870 -- |
871− -- | For example, given a function `height :: Person -> Number`, we can create a function which compares two people by height:
871+ -- | For example, we can create a function which compares two records based on the values of their `x` properties:
872872 -- |
873873 -- | ```purescript
874− -- | taller :: Person -> Person -> Boolean
875− -- | taller = (>) `on` height
874+ -- | compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
875+ -- | compareX = compare `on` _.x
876876 -- | ```
877− -- |
878877 on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
879878 on f g x y = g x `f` g y
880879