Skip to content
This repository was archived by the owner on Aug 15, 2018. It is now read-only.

sugar for creating types #1

Open
mndrix opened this issue Jan 31, 2013 · 3 comments
Open

sugar for creating types #1

mndrix opened this issue Jan 31, 2013 · 3 comments

Comments

@mndrix
Copy link
Owner

mndrix commented Jan 31, 2013

Imagine the following two type definitions in mavis:

:- multifile error:has_type/2.
error:has_type(even_integer, X) :-
    0 is X mod 2.
error:has_type(north_american_country, X) :-
   memberchk(X, [usa, canada, mexico]).

That's more verbose (and error prone) than I'd like. I'd prefer to write:

:- type even_integer ---> 0 is X mod 2.
:- type north_american_country ---> usa; canada; mexico.

The basic notation is similar to Mercury while allowing arbitrary type checks (such as even_integer). This can be implemented with a relatively easy term_expansion/2 macro.

@mndrix
Copy link
Owner Author

mndrix commented Mar 8, 2013

This one is derived from the delta type in my tiny patches project. It's similar to algebraic data types in other languages.

:- type delta ---> +(atom, positive_integer)
                 ; <(positive_integer, oneof([space,tab]), positive_integer)
                 .

which should expand into

:- multifile error:has_type/2.
error:has_type(delta, +(A,B)) :-
    error:has_type(A, atom),
    error:has_type(B, positive_integer).
error:has_type(delta, <(A,B,C)) :-
    error:has_type(positive_integer, A),
    error:has_type(oneof([space,tab]), B),
    error:has_type(positive_integer, C).

@mndrix
Copy link
Owner Author

mndrix commented Dec 26, 2013

Make sure that our type syntax is very close to (if not identical with) the syntax used by Mercury and SWI-Prolog's CHR system.

@mndrix
Copy link
Owner Author

mndrix commented Dec 26, 2013

This sugary syntax should automatically generate clauses for quickcheck:arbitrary/2, if possible. In most circumstances it will be trivial to do so. We certainly don't want to maintain those definitions by hand if we can avoid it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant