Skip to main content

Function declarations

Function declarations allow you to assign concise names to XACML functions and specify their argument types. This information is crucial for the ALFA compiler to perform type checking and type inference for operator overloading. The system.alfa file provides built-in declarations for all standard functions, making it unnecessary for you to declare any.

Here is an example of a function declaration:

function stringEqual = "urn:oasis:names:tc:xacml:1.0:function:string-equal" : string string -> boolean

The declaration consists of the short name, the full XACML identifier, the number and types of the arguments, and the type of the return value.

The possible argument types are:

  • An atomic type that has been declared somewhere, such as string.
  • A bag of a type that has been declared somewhere, such as bag[string].
  • Any atomic type: anyAtomic.
  • A bag of any type: bag[anyAtomic].
  • Any atomic or bag type: anyAtomicOrBag.
  • A function identifier reference: function.

The last argument can optionally be marked with an asterisk (*) to indicate that it may appear zero or any number of times.

Here is a more complex example of a function declaration:

function anyOf = "urn:oasis:names:tc:xacml:1.0:function:any-of" : function anyAtomic bag[anyAtomic] -> boolean

This defines the standard anyOf function. It takes three arguments, the first one being a function reference, the second any atomic value, and the third any bag value. Use of this function could look like the following:

any-of(function[stringEquals], "doctor", Attributes.role)
note

The type declaration is unable to express that for anyOf, as the argument types of the input function (stringEquals) must match the types of the two other arguments. This limitation is there in order to keep the function declaration syntax reasonably simple.

Here is another example:

function anyOfAny3 = "urn:oasis:names:tc:xacml:3.0:function:any-of-any" : function anyAtomicOrBag anyAtomicOrBag* -> boolean

This is the generalized any-of-any function. It accepts a wider range of arguments than anyOf. The first argument is a function reference and then there must be at least one more argument for any atomic or bag type.

The possible return value declarations are:

  • An atomic type that has been declared somewhere, such as: string.
  • A bag of a type that has been declared somewhere, such as bag[string].
  • Any atomic type: anyAtomic.
  • A bag of any type: bag[anyAtomic].
note

In contrast to the input arguments, the function reference and any atomic or bag type are not allowed.