--- layout: default title: "Functions" parent: Abstraction ancestor: Funcons-beta --- [Funcons-beta] : [Functions.cbs] ----------------------------- ### Functions
[
Datatype functions
Funcon function
Funcon apply
Funcon supply
Funcon compose
Funcon uncurry
Funcon curry
Funcon partial-apply
]Meta-variables
T, T′, T1, T2 <: valuesDatatype
functions(T,T′) ::= function(A:abstractions(T=>T′))functions(T, T′) consists of abstractions whose bodies may depend on
a given value of type T, and whose executions normally compute values
of type T′.
function(abstraction(X)) evaluates to a function with dynamic bindings,
function(closure(X)) computes a function with static bindings.
Funcon
apply(_:functions(T, T′), _:T) : =>T′apply(F, V) applies the function F to the argument value V.
This corresponds to call by value; using thunks as argument values
corresponds to call by name. Moreover, using tuples as argument values
corresponds to application to multiple arguments.
supply(F, V) determines the argument value of a function application,
but returns a thunk that defers executing the body of the function.
Rule
supply(function(abstraction(X)), V:T) ~> thunk(abstraction(give(V, X)))compose(F2, F1) returns the function that applies F1 to its argument,
then applies F2 to the result of F1.
Rule
compose(function(abstraction(Y)), function(abstraction(X)))
~> function(abstraction(give(X, Y)))Funcon
uncurry(F:functions(T1, functions(T2, T′))) :
=>functions(tuples(T1, T2), T′)
~> function(abstraction(
apply(
apply(F, checked index(1, tuple-elements given)),
checked index(2, tuple-elements given))))uncurry(F) takes a curried function F and returns a function that takes
a pair of arguments..
Funcon
curry(F:functions(tuples(T1, T2), T′)) : =>functions(T1, functions(T2, T′))
~> function(abstraction(partial-apply(F, given)))curry(F) takes a function F that takes a pair of arguments, and returns
the corresponding 'curried' function.
Funcon
partial-apply(F:functions(tuples(T1, T2), T′), V:T1) : =>functions(T2, T′)
~> function(abstraction(apply(F,tuple(V,given))))partial-apply(F, V) takes a function F that takes a pair of arguments,
and determines the first argument, returning a function of the second
argument.
____
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
[Functions.cbs]: Functions.cbs
"CBS SOURCE FILE"
[Funcons-beta]: /CBS-beta/docs/Funcons-beta
"FUNCONS-BETA"
[Unstable-Funcons-beta]: /CBS-beta/docs/Unstable-Funcons-beta
"UNSTABLE-FUNCONS-BETA"
[Languages-beta]: /CBS-beta/docs/Languages-beta
"LANGUAGES-BETA"
[Unstable-Languages-beta]: /CBS-beta/docs/Unstable-Languages-beta
"UNSTABLE-LANGUAGES-BETA"
[CBS-beta]: /CBS-beta "CBS-BETA"
[PLanCompS Project]: https://plancomps.github.io
"PROGRAMMING LANGUAGE COMPONENTS AND SPECIFICATIONS PROJECT HOME PAGE"
[CBS-beta issues...]: https://github.com/plancomps/CBS-beta/issues
"CBS-BETA ISSUE REPORTS ON GITHUB"
[Suggest an improvement...]: mailto:plancomps@gmail.com?Subject=CBS-beta%20-%20comment&Body=Re%3A%20CBS-beta%20specification%20at%20Values/Abstraction/Functions/Functions.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
"GENERATE AN EMAIL TEMPLATE"