Did you know ... | Search Documentation: |
Packs (add-ons) for SWI-Prolog |
Title: | Type System for Prolog based on Hindley-Milner |
---|---|
Rating: | Not rated. Create the first rating! |
Latest version: | 1.0.3 |
SHA1 sum: | e158d4ae7071dc582e75323ffc1673cf8498ddd1 |
Author: | Tom Schrijvers <Tom.Schrijvers@kuleuven.be> |
No reviews. Create the first review!.
Version | SHA1 | #Downloads | URL |
---|---|---|---|
1.0.3 | e158d4ae7071dc582e75323ffc1673cf8498ddd1 | 36 | https://people.cs.kuleuven.be/~tom.schrijvers/type_check-1.0.3.zip |
1.0.2 | bf33847f88b14927e817832439f026ccf10f4165 | 2 | https://people.cs.kuleuven.be/~tom.schrijvers/type_check-1.0.2.zip |
1.0.1 | a2a1f88e6849fa9467426d610a605ad11f5a6de7 | 68 | http://users.ugent.be/~tschrijv/tor/type_check-1.0.1.zip |
1.0.0 | c4cb8c96d3dddfaddbe03c50cf95b92eabb571b4 | 4 | http://users.ugent.be/~tschrijv/tor/type_check-1.0.0.zip |
We are grateful for useful comments and feedback from:
Define polymorphic algebraic data types like:
:- type pair(A,B) ---> A - B. :- type list(T) ---> [] ; [T|list(T)]. :- type boolean ---> true ; false.
(NOTE: the above types are predefined, as well as integer
and float
.)
Type definitions can also be empty, e.g.
:- type an_empty_type.
This means that the type is not inhabited by instantiated values. Only logical variables are possible.
Predicates are given a signature like:
:- pred append(list(E), list(E), list(E)). :- pred not(boolean, boolean). :- pred lookup(list(pair(Key,Value)), Key, Value).
Optionally, modes can be specified as well, by prefixing
the argument types with +
, -
or ?
. For instance:
:- pred not(+boolean, -boolean).
Note that the type checker fully ignores mode declarations. Hence, mode declarations have not other purpose than to serve as documentation. In particular, the validity of mode declarations is not verified.
:- pred concat(list(list(integer)),list(integer)). concat(LL,L) :- flatten(LL,L) :: flatten(list(list(integer)),list(integer)).
which results in runtime type checking. The annotation is also used for static type checking of the code surrounding the annotated call.
A variant of the annotation is only used for static type checking, and does not result in runtime checks:
concat(LL,L) :- flatten(LL,L) :< flatten(list(list(integer)),list(integer)).
:- trust_pred sort(list(integer),list(integer)).
This signature is only into account when checking calls from typed code.
Untypable code, e.g. using Prolog built-ins, may be encapsulated in a trusted predicate. E.g.
:- trust_pred new_array(list(T),array(T)). new_array(List,Array) :- Array =.. [array|List].
No additional runtime checks are performed for trusted predicates.
Similarly, untyped imported predicates may be given a type signature with the trust_pred declaration.
Options can be passed to the type checker with the declaration
:- type_check_options(Options).
where Options is a list containing zero or more of the following elements:
check(Flag)
where Flag is on
or off
,
to enable or disable the type checker
enabled by defaultruntime(Flag)
where Flag is on
or off
,
to enable or disable runtime type checking
disabled by defaultverbose(Flag)
where Flag is on
or off
,
to enable or disable printed summary at end of type checking
enabled by defaultlist(T)
not defined twicetc_stats(Errors,Total)
Pack contains 4 files holding a total of 43.9K bytes.