The Standard ML Basis Library


The Bool structure


Synopsis

signature BOOL
structure Bool :> BOOL

The Bool structure provides some basic operations on boolean values.


Interface

datatype bool = false | true
val not : bool -> bool
val toString : bool -> string
val scan       : (char, 'aStringCvt.reader
                   -> (bool, 'aStringCvt.reader
val fromString : string -> bool option

Description

not b
returns the logical negation of the boolean value b.

toString b
returns the string representation of b, either "true" or "false".

scan getc strm
fromString s
These scan a character source for a boolean value. The first takes a character stream reader getc and a stream strm. Ignoring case and initial whitespace, the sequences "true" and "false" are converted to the corresponding boolean values. On successful scanning of a boolean value, scan returns SOME(b, rest), where b is the scanned value and rest is the remaining character stream.

The second form scans a boolean from a string s. It returns SOME(b) for a scanned value b; otherwise it returns NONE. The function fromString is equivalent to StringCvt.scanString scan.

See Also

StringCvt

Discussion

The bool type is considered primitive and is defined in the top-level environment. It is rebound here for consistency.

In addition to the not function presented here, the language defines the special operators andalso and orelse, which provide short-circuit evaluation of the AND and OR of two boolean expressions. The semantics of strict AND and OR operators, which would evaluate both expressions before applying the operator, are rarely needed and can easily be obtained using the andalso and orelse operators.


[ Top | Parent | Contents | Index | Root ]

Generated October 02, 2003
Last Modified May 25, 2000
Comments to John Reppy.


This document may be distributed freely over the internet as long as the copyright notice and license terms below are prominently displayed within every machine-readable copy.

Copyright © 2003 AT&T and Lucent Technologies. All rights reserved.

Permission is granted for internet users to make one paper copy for their own personal use. Further hardcopy reproduction is strictly prohibited. Permission to distribute the HTML document electronically on any medium other than the internet must be requested from the copyright holders by contacting the editors. Printed versions of the SML Basis Manual are available from Cambridge University Press. To order, please visit www.cup.org (North America) or www.cup.cam.ac.uk (outside North America).