Next: , Previous: bitmap, Up: Top   [Contents]


11 bool

%--------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%--------------------------------------------------%
% Copyright (C) 1996-1997,2000,2002-2007,2009-2010 The University of Melbourne.
% Copyright (C) 2014-2016, 2018, 2022 The Mercury team.
% This file is distributed under the terms specified in COPYING.LIB.
%--------------------------------------------------%
%
% File: bool.m.
% Main authors: fjh, zs.
% Stability: medium to high.
%
% This module exports the boolean type `bool' and some operations on bools.
%
%--------------------------------------------------%
%--------------------------------------------------%

:- module bool.
:- interface.

:- import_module enum.
:- import_module list.

%--------------------------------------------------%

    % The boolean type.
    % Unlike most languages, we use `yes' and `no' as boolean constants
    % rather than `true' and `false'.  This is to avoid confusion
    % with the predicates `true' and `fail'.
:- type bool
    --->    no
    ;       yes.

:- instance enum(bool).

    % not(A) = yes iff A = no.
    %
:- func not(bool) = bool.
:- pred not(bool::in, bool::out) is det.

    % or(A, B) = yes iff A = yes, or B = yes, or both.
    %
:- func or(bool, bool) = bool.
:- pred or(bool::in, bool::in, bool::out) is det.

    % xor(A, B) = yes iff A = yes, or B = yes, but not both.
    %
:- func xor(bool, bool) = bool.

    % and(A, B) = yes iff A = yes and B = yes.
    %
:- func and(bool, bool) = bool.
:- pred and(bool::in, bool::in, bool::out) is det.

    % or_list(As) = yes iff there exists an element of As equal to yes.
    % (Note that or_list([]) = no.)
    %
:- func or_list(list(bool)) = bool.
:- pred or_list(list(bool)::in, bool::out) is det.

    % and_list(As) = yes iff every element of As is equal to yes.
    % (Note that and_list([]) = yes.)
    %
:- func and_list(list(bool)) = bool.
:- pred and_list(list(bool)::in, bool::out) is det.

    % pred_to_bool(P) = (if P then yes else no).
    %
:- func pred_to_bool((pred)::in((pred) is semidet)) = (bool::out) is det.

%--------------------------------------------------%
%--------------------------------------------------%