<div dir="ltr">Thank you M. McDonough & Zoltan. <br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 24, 2022 at 11:41 AM Zoltan Somogyi <<a href="mailto:zoltan.somogyi@runbox.com">zoltan.somogyi@runbox.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
2022-01-24 09:19 GMT+11:00 "M McDonough" <<a href="mailto:foolkingcrown@gmail.com" target="_blank">foolkingcrown@gmail.com</a>>:<br>
> % I'm putting `dead` as its own functor since it precludes status.<br>
> % This can also make it easier/nicer when using rules for semidet preds.<br>
> % Probably use a 'status' type instead of bools, but for illustration:<br>
> :- type person ---> dead ; alive(awake::bool.bool, free::bool.bool).<br>
<br>
I agree with all this advice, but I would also add a further note,<br>
which is that I would replace the bools here with purpose-specific types.<br>
<br>
With the above type definition, it is too easy to write code such as<br>
Bob = alive(Free, Awake), when the two args should be the other way around.<br>
<br>
With the definitions<br>
<br>
:- type maybe_awake ---> not_awake ; is_awake.<br>
:- type maybe_free ---> not_free ; is_free.<br>
:- type person ---> dead ; alive(awake::maybe_awake, free::maybe_free).<br>
<br>
writing Bob = alive(Free, Awake) is guaranteed to be caught the compiler.<br>
<br>
This requires a minimal amount of extra effort, and that effort will be paid back<br>
at least a hundredfold the first time the compiler tells you exactly where you<br>
mixed up values of two of these types *without* you having to track the bug down<br>
in the debugger.<br>
<br>
Zoltan.</blockquote></div>