Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Хотел сконструировать список кортежей из всех сочетаний элементов трех списков
- -- Типа 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)]
- -- Написал такое:
- genList2h :: a -> [b] -> [(a, b)]
- genList2h a [] = []
- genList2h a (x: xs) = [(a, x)] ++ genList2h a xs
- genList2 :: [a] -> [b] -> [(a, b)]
- genList2 [] _ = []
- genList2 (x: xs) l = genList2h x l ++ genList2 xs l
- tuple2to3 :: a -> (b, c) -> (a, b, c)
- tuple2to3 a (b, c) = (a, b, c)
- genList3h :: a -> [b] -> [c] -> [(a, b, c)]
- genList3h a b c = map (tuple2to3 a) (genList2 b c)
- genList3 :: [a] -> [b] -> [c] -> [(a, b, c)]
- genList3 [] _ _ = []
- genList3 (x: xs) b c = genList3h x b c ++ genList3 xs b c
- -- Можно было
- genList3 a b c = [(x, y, z) | x <- a, y <- b, z <- c]
- -- FFFFFUUUUUUUUU
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement