Next: , Previous: bitmap, Up: Top


11 bool

     %--------------------------------------------------%
     % vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
     %--------------------------------------------------%
     % Copyright (C) 1996-1997,2000,2002-2007,2009-2010 The University of Melbourne.
     % This file may only be copied under the terms of the GNU Library General
     % Public License - see the file COPYING.LIB in the Mercury distribution.
     %--------------------------------------------------%
     %
     % 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).
     
         % or(A, B) = yes iff A = yes, or B = yes, or both.
         %
     :- func bool.or(bool, bool) = bool.
     :- pred bool.or(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 bool.or_list(list(bool)) = bool.
     :- pred bool.or_list(list(bool)::in, bool::out) is det.
     
         % and(A, B) = yes iff A = yes and B = yes.
         %
     :- func bool.and(bool, bool) = bool.
     :- pred bool.and(bool::in, 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 bool.and_list(list(bool)) = bool.
     :- pred bool.and_list(list(bool)::in, bool::out) is det.
     
         % not(A) = yes iff A = no.
         %
     :- func bool.not(bool) = bool.
     :- pred bool.not(bool::in, bool::out) is det.
     
         % xor(A, B) = yes iff A = yes, or B = yes, but not both.
         %
     :- func bool.xor(bool, bool) = bool.
     
         % pred_to_bool(P) = (if P then yes else no).
         %
     :- func pred_to_bool((pred)::((pred) is semidet)) = (bool::out) is det.
     
     %--------------------------------------------------%
     %--------------------------------------------------%