-
Notifications
You must be signed in to change notification settings - Fork 5
2015 005 Addition of Fn module
Author: Andreas Rossberg
Last revised: August 16, 2015
Status: proposed
Discussion: issue #6
signature FN =
sig
val id : 'a -> 'a
val const : 'a -> 'b -> 'a
val apply : ('a -> 'b) * 'a -> 'b
val o : ('b -> 'c) * ('a -> 'b) -> ('a -> 'c)
val curry : ('a * 'b -> 'c) -> ('a -> 'b -> 'c)
val uncurry : ('a -> 'b -> 'c) -> ('a * 'b -> 'c)
val flip : ('a * 'b -> 'c) -> ('b * 'a -> 'c)
val repeat : int -> ('a -> 'a) -> ('a -> 'a)
end
structure Fn : FN-
id x
returns the valuex(idis the polymorphic identity function). -
const x y
returns the value x. -
apply (f, x)
applies the functionftox. Thus, it is equivalent tof a. -
f o g
is the function composition offandg. Thus,(f o g) xis equivalent tof (g x). This function is the same as the globalooperator and is also part of theGeneralstructure. -
curry f x y
is equivalent tof (x, y); i.e.,curry ftransforms the binary functionfinto curried form. -
uncurry f (x, y)
is equivalent tof x y; i.e.,uncurry ftransforms the curried functionfinto a binary function. This function is the inverse ofcurry. -
flip f (x, y)
is equivalent tof (y, x); i.e.,flip fflips the argument order of the binary functionf. -
repeat n f
returns the n-fold composition off. Ifnis less than or equal to zero, thenrepeat n freturns the identity function.
Other combinators could be added. These are the ones that I have needed most in practice.
Adopting this proposal should not affect existing programs.
The need for basic higher-order functions like id and const arises all the time in combination with other functionals.
So far, the SML Basis has lacked any of these functions, although they are standard in the libraries of most other functional programming languages.
This module also provides a more natural home for the existing o operator, but it would also
remain in the General structure for backward compatibility.
-
[2015-08-21] Reworked function descriptions to follow standard style [JHR].
-
[2015-08-16] Proposed
