In the previous chapter the basic idea behind abstraction and application was already discussed. This chapter will explore how these concepts can be used in Tony.
Here is how you can abstract operations:
In its current version, Tony does not yet come with a standard library. That means that any abstraction you use also has to be defined by yourself. You can use the
eval('console.log') returns an abstraction that if applied to prints to
Operator & Identifier
Before we move on to make use of our abstractions by applying arguments to them, we have to make an important distinction.
Other than in most programming languages in Tony operators like
* are identifiers, This means that their value has to be defined before use in the same way as the value of a regular identifier like
Here is how to apply arguments to an abstraction:
Infix applications are useful when applying to an abstraction expecting two arguments.
Note here that regular identifiers are surrounded by ` when used in infix applications.
Prefix applications are can be used to apply a single argument to an operator without parentheses.
Prefix application can only be used for operators and not for regular identifiers.
Tony curries the parameters of abstractions. This means that whenever multiple arguments are applied to an abstraction at the same time, Tony will instead apply these argumentes ony by one. Whenever an argument is applied and there remain parameters that have not been satisfied, a new abstraction is returned that relects the already applied arguments. This process is also called partial application.
Partial application allows for arguments to be applied to an abstraction one by one.
? can be used as a placeholder to skip the application of a specific parameter.