Browse thread
camlp4
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Nicolas Pouillard <nicolas.pouillard@g...> |
| Subject: | Re: [Caml-list] camlp4 |
Excerpts from christian.sternagel's message of Fri Jan 18 18:08:52 +0100 2008:
> When using `camlp4o -parser Camlp4ListComprehension' as preprocessor,
> is the resulting code the naive translation, like in,
>
> [(x, y) | x <- xs, even xs, y <- ys]
>
> =>
>
> List.flatten (
> List.map (fun x -> List.map (fun y -> (x, y)) ys) (List.filter even xs)
> )
>
> or is there an optimization in order to avoid appends and minimize the
> number of cons?
There is only a few very local optimizations.
However you can answer to your question by asking camlp4 to translate your
code and pretty-print the result.
$ camlp4o -parser Camlp4ListComprehension -str '[(x, y) | x <- xs; even xs; y <- ys]'
List.concat
(List.map (fun x -> List.map (fun y -> (x, y)) ys)
(List.filter (fun x -> even xs) xs))
As you can see List.concat is still there.
Note also that the syntax is to use `;' to separate qualifiers (generators
and filters) instead of `,' as your example.
Best regards,
--
Nicolas Pouillard aka Ertai