Haskell : タプルとリストの相互変換

-- convertlist.hs
-- 各種convertのプログラム。-> 練習問題
-- 1.タプルとリストの相互変換 -> [[1,2],[3,4]] -> [(1,2),(3,4)]
-- 2.タプルから2つのリストへ相互変換 -> [(1,'a'),(2,'b')] -> [1,2]['a','b']
-- 3.タプルからフラットリストへ相互変換 -> [(1,2),(3,4)] -> [1,2,3,4]
-- 4.任意の長さのタプルとリストの相互変換 -> (1,2,3,4) -> [1,2,3,4]
-- 5.リストからすべての組み合わせのタプルをつくる
-- 6.タプルから要素を抜き出してリストをつくる


-- concat flattens a list 1 tier at a time
-- concat [[1,2],[3,4]] -> [1,2,3,4]
-- implement concat'
concat' :: a -> [a]
concat'[ ] = [ ]
concat' (x:xs) = x ++ concat' (xs)

-- tuppleToList
-- tuppleToList [(1,2),(3,4)] -> [[1,2],[3,4]]
tuppleToList :: [(t, t)] -> [ [ t ] ]
tuppleToList = map (\(x,y) -> [x,y])

-- listToTupple
-- listToTupple [[1,2],[3,4]] -> [(1,2),(3,4)]
listToTupple :: [ [ t ] ] -> [(t, t)]
listToTupple = map (\[x,y] -> (x,y))

-- tuppleToTwoList
-- tuppleToTwoList [(1,'a'),(2,'b')] -> ([1,2], ['a','b'])
-- Prelude has zip and unzip
-- zip [1,2] ['a','b'] -> [(1,'a'),(2,'b')]
-- unzip [(1,'a'),(2,'b)] -> ([1,2],"ab")

-- tuppleToFlatList
-- tuppleToFlatList [(1,2),(3,4)] -> [1,2,3,4]
-- (concat.tuppleToList) [(1,2),(3,4)] -> [1,2,3,4]

-- tuppleToList4
-- tuppleToList4 (1,2,3,4) -> [1,2,3,4]
tuppleToList4 :: (a,a,a,a) -> [a]; tuppleToList4 (a,b,c,d) = [a,b,c,d]

-- make all the combination from a list
-- using list comprehension
-- (\ xs -> [(x, y) | x <- xs, y <- xs, x /= y]) ['a', 'b', 'c']
-- > [('a','b'),('a','c'),('b','a'),('b','c'),('c','a'),('c','b')]

-- filter from tupple list
-- map snd $ filter (odd.fst) [(1, 'a'), (2, 'b'), (3, 'c')]
-- "ac"