[m-users.] Mercury for Game AI

Zoltan Somogyi zoltan.somogyi at runbox.com
Mon Jan 24 20:41:38 AEDT 2022


2022-01-24 09:19 GMT+11:00 "M McDonough" <foolkingcrown at gmail.com>:
> % I'm putting `dead` as its own functor since it precludes status.
> % This can also make it easier/nicer when using rules for semidet preds.
> % Probably use a 'status' type instead of bools, but for illustration:
> :- type person ---> dead ; alive(awake::bool.bool, free::bool.bool).

I agree with all this advice, but I would also add a further note,
which is that I would replace the bools here with purpose-specific types.

With the above type definition, it is too easy to write code such as
Bob = alive(Free, Awake), when the two args should be the other way around.

With the definitions

:- type maybe_awake ---> not_awake ; is_awake.
:- type maybe_free ---> not_free ; is_free.
:- type person ---> dead ; alive(awake::maybe_awake, free::maybe_free).

writing Bob = alive(Free, Awake) is guaranteed to be caught the compiler.

This requires a minimal amount of extra effort, and that effort will be paid back
at least a hundredfold the first time the compiler tells you exactly where you
mixed up values of two of these types *without* you having to track the bug down
in the debugger.

Zoltan.


More information about the users mailing list