Advertisement
karlicoss

FFFFUUUUUU

Jul 8th, 2011
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Хотел сконструировать список кортежей из всех сочетаний элементов трех списков
  2. -- Типа genList3 [1, 2, 3] ['a', 'b'] [True] = [(1, 'a', True), (1, 'b', True), (2, 'a', True), (2, 'b', True), (3, 'a', True), (3, 'b', True)]
  3. -- Написал такое:
  4. genList2h :: a -> [b] -> [(a, b)]
  5. genList2h a []       = []
  6. genList2h a (x: xs) = [(a, x)] ++ genList2h a xs
  7.  
  8. genList2 :: [a] -> [b] -> [(a, b)]
  9. genList2 [] _ = []
  10. genList2 (x: xs) l = genList2h x l ++ genList2 xs l
  11.  
  12. tuple2to3 :: a -> (b, c) -> (a, b, c)
  13. tuple2to3 a (b, c) = (a, b, c)
  14.  
  15. genList3h :: a -> [b] -> [c] -> [(a, b, c)]
  16. genList3h a b c = map (tuple2to3 a) (genList2 b c)
  17.  
  18. genList3 :: [a] -> [b] -> [c] -> [(a, b, c)]
  19. genList3 [] _ _ = []
  20. genList3 (x: xs) b c = genList3h x b c ++ genList3 xs b c
  21.  
  22. -- Можно было
  23. genList3 a b c = [(x, y, z) | x <- a, y <- b, z <- c]
  24. -- FFFFFUUUUUUUUU
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement