[Haskell-beginners] List Function
Edward Z. Yang
ezyang at MIT.EDU
Wed Apr 29 22:41:15 EDT 2009
Excerpts from Edward Z. Yang's message of Wed Apr 29 22:38:40 -0400 2009:
> Excerpts from Nathan Holden's message of Wed Apr 29 22:25:43 -0400 2009:
> > Sending two lists, [1,2,3] and [2,3,4] it would return
> > [(1,4),(1,5),(1,6),(2,4),(2,5),(2,6),(3,4),(3,5),(3,6)]. I managed to code
> > my way into returning a list of lists, which works. But it seemed like a
> > very basic list/matrix function, so I honestly believe that the Haskell
> > designers probably would've put it in.
>
> Did you mean [1,2,3] and [4,5,6]?
To elaborate, a list comprehension is what you want, if you want this function
to do what I think you want it to do.
Prelude> let f as bs = [(a,b) | a <- as, b <- bs]
Prelude> f [1,2,3] [4,5,6]
[(1,4),(1,5),(1,6),(2,4),(2,5),(2,6),(3,4),(3,5),(3,6)]
Cheers,
Edward
More information about the Beginners
mailing list