Parallel list comprehensions

Cale Gibbard cgibbard at gmail.com
Mon Feb 6 01:23:37 EST 2006


Oh, sorry about that. I posted too quickly, and hadn't noticed that
was the original intention.

 - Cale

On 05/02/06, Jon Fairbairn <jf at cl.cam.ac.uk> wrote:
> On 2006-02-04 at 16:08EST Cale Gibbard wrote:
> > cartesian xs ys = map (\[x,y] -> (x,y)) $ sequence [xs,ys]
>
> I'm lost. Isn't that just like
> cartesian xs ys = [(x,y)|x<-xs, y<-ys]
> ?
>
> Whereas...
> > On 04/02/06, Jan-Willem Maessen <jmaessen at alum.mit.edu> wrote:
> > >
> > > On Feb 4, 2006, at 1:31 PM, Jon Fairbairn wrote:
> > > > ...
> > > > There ought to be a list_product somewhere (I mean [1..]
> > > > `list_product` [4..] ==
> > > > [(1,4),(2,4),(1,5),(3,4),(2,5),(1,6),...]). Is there?
> > >
> > > Not that I know of, but here's one which handles finite lists
> > > correctly; it'd be a nice addition to Data.List:
> > >
> > > dzip :: [a] -> [b] -> [(a,b)]
> > > dzip =  dzipWith (,)
> > >
> > > dzipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
> > > dzipWith f [] ys = []
> > > dzipWith f as [] = []
> > > dzipWith f as (y:ys) = dzipK ys [y]
> > >    where dzipK (b:bs) rbs =
> > >              zipWith f as rbs ++ dzipK bs (b : rbs)
> > >          dzipK []     rbs = dzipT as
> > >            where dzipT ys@(_:yt) = zipWith f ys rbs ++ dzipT yt
> > >                  dzipT []     = []
> > >
> > > -Jan-Willem Maessen
>
> ...does seem to work for infinite lists!
> --
> Jón Fairbairn                              Jon.Fairbairn at cl.cam.ac.uk
>
>
>


More information about the Haskell-prime mailing list