Language extension idea (was Re: [Haskell-cafe] Re: OCaml list
sees...)
J. Garrett Morris
J.Garrett.Morris at Dartmouth.EDU
Sun Oct 10 18:45:55 EDT 2004
--- Malcolm Wallace wrote:
As an example, instead of the following list-only code,
f :: List a -> ...
f [] = ...
f (h:t) = ...
you could write this more general version, which assumes only some
class Sequence with operations null, head, tail, etc.
f :: Sequence s => s a -> ...
f list | null list = ...
| h <- head list, t <- tail list = ...
--- end of quote ---
I guess that's about half way there. I (and, I think, the original poster) was thinking more along the lines of generalizing the existing interface and considering lazy lists to be one implementation. It seems like the "list" syntax is general enough to apply to any ordered collection. Further, that would only require minimal changes in large amounts of existing code that relies on, for example, Strings being [Char]s were Strings changed to a more efficient representation. /gXm
More information about the Haskell-Cafe
mailing list