The Standard ML Basis Library

The Bool structure


signature BOOL
structure Bool :> BOOL

The Bool structure provides some basic operations on boolean values.


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


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



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 April 12, 2004
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 © 2004 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 (North America) or (outside North America).