From e8f7bb0db1b5ed5e241f3780a6761dd6f5104652 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 10 Mar 2012 18:01:01 -0800 Subject: [PATCH] core: Cleanup bool module Instead of defining a type for bool, just use the bool type directly in order to be more consistent with other modules. Cleanup the comments a bit. --- src/libcore/bool.rs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/libcore/bool.rs b/src/libcore/bool.rs index 4ceb384d7aa..42df0e29a99 100644 --- a/src/libcore/bool.rs +++ b/src/libcore/bool.rs @@ -1,46 +1,46 @@ // -*- rust -*- -#[doc = "Classic Boolean logic reified as ADT"]; +#[doc = "Boolean logic"]; -export t; export not, and, or, xor, implies; export eq, ne, is_true, is_false; export from_str, to_str, all_values, to_bit; -#[doc = "The type of boolean logic values"] -type t = bool; - -#[doc = "Negation/Inverse"] -pure fn not(v: t) -> t { !v } +#[doc = "Negation / inverse"] +pure fn not(v: bool) -> bool { !v } #[doc = "Conjunction"] -pure fn and(a: t, b: t) -> t { a && b } +pure fn and(a: bool, b: bool) -> bool { a && b } #[doc = "Disjunction"] -pure fn or(a: t, b: t) -> t { a || b } +pure fn or(a: bool, b: bool) -> bool { a || b } -#[doc = "Exclusive or, i.e. `or(and(a, not(b)), and(not(a), b))`"] -pure fn xor(a: t, b: t) -> t { (a && !b) || (!a && b) } +#[doc = " +Exclusive or + +Identical to `or(and(a, not(b)), and(not(a), b))` +"] +pure fn xor(a: bool, b: bool) -> bool { (a && !b) || (!a && b) } #[doc = "Implication in the logic, i.e. from `a` follows `b`"] -pure fn implies(a: t, b: t) -> t { !a || b } +pure fn implies(a: bool, b: bool) -> bool { !a || b } #[doc = " true if truth values `a` and `b` are indistinguishable in the logic "] -pure fn eq(a: t, b: t) -> bool { a == b } +pure fn eq(a: bool, b: bool) -> bool { a == b } #[doc = "true if truth values `a` and `b` are distinguishable in the logic"] -pure fn ne(a: t, b: t) -> bool { a != b } +pure fn ne(a: bool, b: bool) -> bool { a != b } #[doc = "true if `v` represents truth in the logic"] -pure fn is_true(v: t) -> bool { v } +pure fn is_true(v: bool) -> bool { v } #[doc = "true if `v` represents falsehood in the logic"] -pure fn is_false(v: t) -> bool { !v } +pure fn is_false(v: bool) -> bool { !v } #[doc = "Parse logic value from `s`"] -pure fn from_str(s: str) -> option { +pure fn from_str(s: str) -> option { alt check s { "true" { some(true) } "false" { some(false) } @@ -49,19 +49,19 @@ pure fn from_str(s: str) -> option { } #[doc = "Convert `v` into a string"] -pure fn to_str(v: t) -> str { if v { "true" } else { "false" } } +pure fn to_str(v: bool) -> str { if v { "true" } else { "false" } } #[doc = " Iterates over all truth values by passing them to `blk` in an unspecified order "] -fn all_values(blk: fn(v: t)) { +fn all_values(blk: fn(v: bool)) { blk(true); blk(false); } #[doc = "converts truth value to an 8 bit byte"] -pure fn to_bit(v: t) -> u8 { if v { 1u8 } else { 0u8 } } +pure fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } } #[test] fn test_bool_from_str() {