-2

I just cant find a way to generate tuples in element R like (1,2) Thats should make <1,1>,<1,2><2,1><2,2>

  • Sorry, what exactly is `R` in this context? – Louis Wasserman Sep 08 '22 at 18:04
  • Better expained i have x={1,2} y={1,2} And i want to generate tuples from my list X*Y – bibo mastar bibomastar Sep 08 '22 at 18:15
  • There is a well known functional pearl for generating an infinite tree of (provably) every rational number, lazily: https://www.cs.ox.ac.uk/ralf.hinze/publications/Bird.pdf. As it mentions, there's also the [Stern–Brocot tree](https://en.wikipedia.org/wiki/Stern–Brocot_tree) and [Calkin-Wilf tree](https://en.wikipedia.org/wiki/Calkin–Wilf_tree) – Axman6 Sep 23 '22 at 05:07

1 Answers1

3

The shortest and most convenient way to take two lists x and y and generate tuples from them is

liftM2 (,) x y

The most self-explanatory way to do this is

[(a, b) | a <- x, b <- y]
Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413