Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Efficiency of 'a list
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Cannasse <warplayer@f...>
Subject: Re: [Caml-list] Two types of efficiency (Was Efficiency of 'a list)
> > Few people here are currently running the "ExtLib" - ocaml extended
> > library - project, and are trying to answer theses questions. For an
> > example of a structure that can be used to convert from and between
> > several different data structures, you could have a look at the Enum
> > module from the ExtLib CVS here :
>
> I read the code but I am afraid I didn't catch the point : what is the
> difference between the 'enum' data structure and a ('a * int) stream ?

I agree that an Enum is near from a Stream, but it differs in several points
:
- as it is purely functional, you can create quite exotic count and next
functions, while Stream.from is only working with indexes, and is having a
little cost due to the usage of 'a option instead of an exception.
- Enum provide easy support for functional operations such as map, while
doing it with stream require a little bit of thinking (and from usage)
- with a stream, you have access to a "next" functions : you cannot do
something like this with Enum . In most cases, you always want to process
all your elements in the same way. Enum does not provide user access to
next, you can only do iter.

In a short way : Stream is designed more as a "tokenizer" where you're
querying items one by one, while Enum is more an uniform collection of
items, abstracted in a purely fonctional way.

> Why is it more convenient than other data structures as an itermediate
> data representation ?

It's not a data structure since it does not physically store any elements,
it can be seen as a common interface from different data structures wanting
to provide support for it. See ExtList.of_enum , ExtList.enum,
ExtArray.of_enum and ExtArray.enum , one can do the following :

let e = ExtList.enum l in
let e' = Enum.map f e in
ExtArray.of_enum e'

To map-and-convert a list to an array. Quite convenient in fact, but I agree
Enum is not the Graal of functionnal programming, just a small convenient
interface.

Nicolas Cannasse

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners