The ListFormat
structure provides some utility functions for converting
lists into strings (and back).
Synopsis
signature LIST_FORMAT
structure ListFormat : LIST_FORMAT
Interface
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
Description
val fmt : { … } -> 'a list -> string
-
fmt {init, sep, final, fmt} lst
converts the listlst
to a string, whereinit
is an initial string,sep
is the separator,final
is the final string, andfmt
is a function for converting the list elements to strings. For the list value[a, b, …, c]
, the resulting string will be formatted asinit ^ (fmt a) ^ sep ^ (fmt b) ^ sep ^ ... ^ sep ^ (fmt c) ^ final
val listToString : ('a -> string) -> 'a list -> string
-
listToString fmt lst
returns a string representinglst
using SML's list notation. In other words, the above expression is equivalent tofmt {init="[", sep=",", final="]", fmt=fmt} lst
val scan : { … } -> (char, 'b) StringCvt.reader -> ('a list, 'b) StringCvt.reader
-
scan {init, sep, final, scan} getc
returns areader
for scanning lists of items from a character stream. The resulting reader expects the list to begin with theinit
string, usesep
as a separator, and end with thefinal
string. The reader uses thescan
argument function to scan individual list elements.
The reader will skip extra whitespace, so to scan a list of items separated by spaces, use the empty string (""
) as the separator.