What is a deep list, exactly? (was: length of an iolist)
Mon Aug 15 23:56:13 CEST 2005
Mark Scandariato wrote:
>>From the current docs (.../erl5.4.8/lib/kernel-2.10.9/doc/html/erlang.html):
> "Some BIFs, such as list_to_binary_1, take I/O lists as documents (written as iolist()
> in type descriptions). An I/O list is a deep list of binaries, integers in the range
> 0 through 255, and other I/O lists. In an I/O list, a binary is allowed as the tail
> of a list."
> PS: I agree that a single binary would be a reasonable thing to pass to such a
> function - but the docs appear to differ.
If I understand correctly, a deep list (in general, not specific
to Erlang) is isomorphic to a binary tree where each node is labelled
with either the element type or Nil. In Haskell-ish notation:
deeplist t ::= t | Nil | Cons (deeplist t) (deeplist t)
where in this case t = binary | char. ('|' means type union, not cons.)
seems to confirm that this is the definition Scheme people use.
In that case, a single binary would be an iolist (as would a single char).
But this seems not to be the definition intended for Erlang, although it's
not exactly clear from the above docs. Reading the docs literally it would
be something like:
iolist ::= Nil | Cons (char | binary | iolist) (binary | iolist)
Is that right? If so it seems, well, ugly.
David Hopwood <>
More information about the erlang-questions