SML/NJ Library Manual

The ListFormat structure


signature LIST_FORMAT
structure ListFormat : LIST_FORMAT

The ListFormat structure provides simple utilities for converting between lists and their string representations.


val fmt : {init : string, sep : string, final : string, fmt : 'a -> string} -> 'a list -> string
val listToString : ('a -> string) -> 'a list -> string
val scan : {init : string, sep : string, final : string, scan : (char,'b) StringCvt.reader -> ('a,'b) StringCvt.reader} -> (char,'b) StringCvt.reader -> ('a list,'b) StringCvt.reader


fmt {init, sep, final, fmt}
takes an initial string (init), a separator (sep), a terminating string (final), and an item formating function (fmt), and returns a list formatting function. The list [a, b, ..., c] gets formated as
          init ^ (fmt a) ^ sep ^ (fmt b) ^ sep ^ ... ^ sep ^ (fmt c) ^ final

listToString f l
formats a list in SML style. Equivalent to:
          fmt {init="[", sep=",", final="]", fmt=f} l

scan {init, sep, final, scan} re
scans a list of the specified format from a stream of characters. If successful, it returns the list and the remainder of the stream; otherwise, it returns NONE.

The format of the list is specified by an expected initial string init, a list item separator sep, an expected terminating string final, and a function scan for scanning a list item. Whitespace is ignored.

When scanning a string, scan checks for the separator before the terminator, thus if the separator is a prefix of the terminator, the function will not work.

See Also

Format, List, StringCvt

[ Top | Parent | Contents | Index | Root ]

Last Modified June 11, 1998
Comments to John Reppy
Copyright © 1998 Bell Labs, Lucent Technologies