Ground terms and modes of use

A term that contains no variable is said to be ground. [1,a,-6,"hi"] is a ground list term of type list(integer || atom || string). The terms [1,a, U,"hi"] and [1,a,-6,..L] are not ground. The type checker ensures that all function calls are given ground arguments of their declared argument types, and that they will return a ground value of the declared value type. It checks that each relation and action call will have each argument an unbound variable, or a term of the declared type. It also checks that the argument will be a ground term before the call if moded ! (ground input), and will be ground after the successful evaluation of the call, if moded ? (ground output). Only if moded with ?? (non-ground output) is there no check beyond the type check. A @ moded argument is one where the argument will not be further instantiated by the call.

Relations and actions (defined by one or more rules) have a sub-type relationship based on this data sub-type relationships and their modes of use, specified by their moded argument types. For functions the sub-type relation just depends on argument and value types as there is only one mode of use - all arguments ground and ground value returned. As an example of the role of modes, suppose the higher order argument type specifies the relation given as an argument will only be used to check integer values. We can pass in a relation that checks or generates number values. A more flexible check or generate relation that handles numbers can be used where only integer values will be tested.

QuLog is a fully integrated LP/FP language in that function calls can appear as or inside arguments to relation calls, and relational queries can be used as tests in function rules, and in set expression arguments of function calls.

The compiler does type checking of function, relation and action definitions, assisted by type inference for data terms and variables. We believe that type declarations, linked with mode of use declarations for relations and action procedures, are very useful active documentation of the program. Also, because we have union types and sub-types, type inference on code could be very complex in some cases. Type inference on data terms will assign the term the minimum type in the sub-type lattice.

This user guide assumes familiarity with Prolog and higher order functional programming, as in languages such as Haskell or Scala.

In Section 3 we briefly discuss syntax and in Section 4 we discuss type declarations. In Section 5 we discuss the relation rule part of QuLog , in Section 6 we discuss the function rule part and in Section 7 we discuss the action rule part of QuLog. Lastly, in Section 8 we give examples of using the QuLog interpreter.

All QuLog and TeleoR program files use the .qlg extension. The QuLog examples below are nearly all from the file examples/introduction/qlexamples.qlg