タプルのリストを作成しようとしています。入力はタプルのリストで[([char], int1, int2), ...]
あり、出力は次のようなタプルのリストです[([char], int1, int2, (int1/int2)), ...]
。タプルのリストのリストを作成していると思うので、以下のコードが間違っていることを知っています[[(),(),(),()], [(),(),(),()]]
。
コード:
{- take a list of labels, values, and weights and return list of labels and fractions -}
fraclist [] = []
fraclist x = [ (y,r,q,z) : y <- first (head x) | r <- scnd (head x) | q <- last (head x) | z <- r/q ] : fraclist tail x
{- helper func to get values from tuples -}
frst (a,b,c) = a
scnd (a,b,c) = b
last (a,b,c) = c
説明されている適切な出力フォームを取得するにはどうすればよいですか?また、zが降順になるように順序付けられたタプルのリストを出力するにはどうすればよいですか?