Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
While writing down theories, it is very common that multiple expressions take on the same form. Luckily it is possible to abstract these away using functions.
Note that function application is done by just writing a space between the function and the argument.
Warning: Equality and comparisons between functions is not guaranteed to give any useful result.
It is also possible to use infix notation for binary function application. In this case you need to write your function name between backticks
a `plus` b
It is also possible to define a function and not give it a name, this is done with a backslash. Note that just like let-constructs, functions also introduce a local scope so the
x within the function definition is not the same as the
x we are defining.
A function declaration:
f a b := g a b is actually syntactical sugar for
f := (\a -> (\b -> g a b)).
If a function takes two arguments, it is not necesary to apply them to both at once. You can reuse a partially applied function multiple times like this:
The other way around
Similarly to constraints with variables, IDP4 allows the introduction of unknown functions that take a value satisfying the given constraints. You can declare a function with the statement:
name :: function to setExpression.
A special case are Boolean functions, also known as predicates. Again, as with propositions, IDP4 has efficient support predicates through the declaration
name :: predicate.