/*---------------------------------------------------------------------------
  Copyright 2012-2024, Microsoft Research, Daan Leijen.

  This is free software; you can redistribute it and/or modify it under the
  terms of the Apache License, Version 2.0. A copy of the License can be
  found in the LICENSE file at the root of this distribution.
---------------------------------------------------------------------------*/

// Standard `:bool` functions.
//
// Booleans are either `True` or `False`.
module std/core/boolstd/core/bool

import std/core/typesstd/core/types

// ----------------------------------------------------------------------------
// Booleans
// ----------------------------------------------------------------------------

pub fip fun (==)std/core/bool/(==): (x : bool, y : bool) -> bool( xx: bool : boolstd/core/types/bool: V, yy: bool : boolstd/core/types/bool: V)result: -> total bool : boolstd/core/types/bool: V
  if xx: bool then yy: bool else !std/core/types/bool/(!): (b : bool) -> boolyy: bool

pub fip fun (!=)std/core/bool/(!=): (x : bool, y : bool) -> bool( xx: bool : boolstd/core/types/bool: V, yy: bool : boolstd/core/types/bool: V)result: -> total bool : boolstd/core/types/bool: V
  if xx: bool then !std/core/types/bool/(!): (b : bool) -> boolyy: bool else yy: bool

pub fip fun (<)std/core/bool/(<): (x : bool, y : bool) -> bool( xx: bool : boolstd/core/types/bool: V, yy: bool : boolstd/core/types/bool: V)result: -> total bool : boolstd/core/types/bool: V
  (!std/core/types/bool/(!): (b : bool) -> boolxx: bool &&std/core/types/(&&): (x : bool, y : bool) -> bool yy: bool)

pub fip fun (<=)std/core/bool/(<=): (x : bool, y : bool) -> bool( xx: bool : boolstd/core/types/bool: V, yy: bool : boolstd/core/types/bool: V)result: -> total bool : boolstd/core/types/bool: V
  !std/core/types/bool/(!): (b : bool) -> bool(xx: bool >std/core/bool/(>): (x : bool, y : bool) -> bool yy: bool)

pub fip fun (>)std/core/bool/(>): (x : bool, y : bool) -> bool( xx: bool : boolstd/core/types/bool: V, yy: bool : boolstd/core/types/bool: V)result: -> total bool : boolstd/core/types/bool: V
  (xx: bool &&std/core/types/(&&): (x : bool, y : bool) -> bool !std/core/types/bool/(!): (b : bool) -> boolyy: bool)

pub fip fun (>=)std/core/bool/(>=): (x : bool, y : bool) -> bool( xx: bool : boolstd/core/types/bool: V, yy: bool : boolstd/core/types/bool: V)result: -> total bool : boolstd/core/types/bool: V
  !std/core/types/bool/(!): (b : bool) -> bool(xx: bool <std/core/bool/(<): (x : bool, y : bool) -> bool yy: bool)

// Compare two booleans with `False < True`.
pub fip fun cmpstd/core/bool/cmp: (x : bool, y : bool) -> order( xx: bool : boolstd/core/types/bool: V, yy: bool : boolstd/core/types/bool: V)result: -> total order : orderstd/core/types/order: V
  if xx: bool <std/core/bool/(<): (x : bool, y : bool) -> bool yy: bool then Ltstd/core/types/Lt: order
  elif xx: bool >std/core/bool/(>): (x : bool, y : bool) -> bool yy: bool then Gtstd/core/types/Gt: order
  else Eqstd/core/types/Eq: order

// Order two booleans in ascending order.
pub fip fun order2std/core/bool/order2: (x : bool, y : bool) -> order2<bool>( xx: bool : boolstd/core/types/bool: V, yy: bool : boolstd/core/types/bool: V )result: -> total order2<bool> : order2std/core/types/order2: V -> V<boolstd/core/types/bool: V>
  if (xx: bool==std/core/bool/(==): (x : bool, y : bool) -> boolyy: bool) then Eq2std/core/types/Eq2: forall<a> (eq : a) -> order2<a>(xx: bool) elif (xx: bool <std/core/bool/(<): (x : bool, y : bool) -> bool yy: bool) then Lt2std/core/types/Lt2: forall<a> (lt : a, gt : a) -> order2<a>(xx: bool,yy: bool) else Gt2std/core/types/Gt2: forall<a> (lt : a, gt : a) -> order2<a>(yy: bool,xx: bool)


// Convert a `:bool` to a string
pub fun showstd/core/bool/show: (b : bool) -> string( bb: bool : boolstd/core/types/bool: V )result: -> total string : stringstd/core/types/string: V
  if bb: bool then "True"literal: string
count= 4
else "False"literal: string
count= 5
// Convert a boolean to an `:int` pub fip fun intstd/core/bool/int: (b : bool) -> int( bb: bool : boolstd/core/types/bool: V )result: -> total int : intstd/core/types/int: V if bb: bool then 1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
else
0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000