* [Caml-list] Feature Wish: List comprehensions
@ 2006-03-30 8:38 Jonathan Roewen
2006-03-30 19:02 ` Martin Jambon
0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Roewen @ 2006-03-30 8:38 UTC (permalink / raw)
To: OCaml
Hi,
I'm having a small problem trying to tidily define an equivalent
function to some Haskell code.
Haskell:
pThen combine p1 p2 toks
= [ (combine v1 v2, toks2) | (v1,toks1) <- p1 toks, (v2, toks2) <- p2 toks1 ]
(I'll also be needing to specify equivalents for pThen3 & pThen4).
The first isn't too bad...
let pThen combine p1 p2 = fun ts ->
let l1 = p1 ts in
let l2 = List.map (fun (v1,ts1) -> p2 ts1) l1 in
List.concat
(List.map2 (fun (v1,ts1) l2 -> List.map (fun (v2,ts2) -> combine
v1 v2,ts2) l2) l1 l2)
As you can see, extending this style to pThen3 & pThen4 is going to be
very, very ugly (and hard to get right first time).
I know it's just shorthand for map/filter, (and more complex
derivatives of these), but it would be nice to have in ocaml...
BTW: any suggestions on a better way to write the above function would
be appreciated ;-)
Kindest Regards,
Jonathan Roewen
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Feature Wish: List comprehensions
2006-03-30 8:38 [Caml-list] Feature Wish: List comprehensions Jonathan Roewen
@ 2006-03-30 19:02 ` Martin Jambon
0 siblings, 0 replies; 2+ messages in thread
From: Martin Jambon @ 2006-03-30 19:02 UTC (permalink / raw)
To: Jonathan Roewen; +Cc: OCaml
There's a camlp4 lib for this:
http://oandrieu.nerim.net/ocaml/#pa_compr
If you use ocamlfind, you might want install it with p4ck, which also
installs a few other camlp4 hacks from various authors.
(http://martin.jambon.free.fr/p4ck.html)
Martin
On Thu, 30 Mar 2006, Jonathan Roewen wrote:
> Hi,
>
> I'm having a small problem trying to tidily define an equivalent
> function to some Haskell code.
>
> Haskell:
> pThen combine p1 p2 toks
> = [ (combine v1 v2, toks2) | (v1,toks1) <- p1 toks, (v2, toks2) <- p2 toks1 ]
>
> (I'll also be needing to specify equivalents for pThen3 & pThen4).
>
> The first isn't too bad...
>
> let pThen combine p1 p2 = fun ts ->
> let l1 = p1 ts in
> let l2 = List.map (fun (v1,ts1) -> p2 ts1) l1 in
> List.concat
> (List.map2 (fun (v1,ts1) l2 -> List.map (fun (v2,ts2) -> combine
> v1 v2,ts2) l2) l1 l2)
>
> As you can see, extending this style to pThen3 & pThen4 is going to be
> very, very ugly (and hard to get right first time).
>
> I know it's just shorthand for map/filter, (and more complex
> derivatives of these), but it would be nice to have in ocaml...
>
> BTW: any suggestions on a better way to write the above function would
> be appreciated ;-)
>
> Kindest Regards,
>
> Jonathan Roewen
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
--
Martin Jambon, PhD
http://martin.jambon.free.fr
Edit http://wikiomics.org, bioinformatics wiki
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-03-30 19:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-30 8:38 [Caml-list] Feature Wish: List comprehensions Jonathan Roewen
2006-03-30 19:02 ` Martin Jambon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox