我有以下列表:
articles
我有一个名为articles=["HP","Haskell"]
的名单。
我想用元组转换上面的列表,这样如果我有(长篇文章)倍于列表中出现的元组的第一个元素,那就得到它!
因此,例如,如果我有一个列表[(Proxis,20.0),(Proxis,45.0)]
,则列表应显示:
Proxis
因为data Magasin = Proxis | Amazon | Libri deriving (Eq, Show)
type Article = String
type Prix = Float
data Entree = E Magasin Article Prix deriving (Eq, Show)
type Stock = [Entree]
出现了两次!
编辑:
数据类型:
disponible::[Article]->Stock->[(Magasin,Float)]
disponible [] stk = []
disponible (art:reste) stk = (foldl(\acc (E m a p)->if a==art then (m,p):acc else acc) [] stk)++(disponible reste stk)
这是我目前的代码:
disponible::[Article]->Stock->[(Magasin,Float)]
disponible articles stock = map(\(m,ls)->(m,sum $ map (\(E _ _ p)->p) ls)) $ filter ((==length articles).length.snd) magasinsArticles
where contientArticles = (filter (\(E _ a _)->a`elem`articles) stock)
magasins = foldl (\acc e-> if e`elem`acc then acc else (e:acc)) [] $ map (\(E m _ _)->m) contientArticles
magasinsArticles = map (\m->(m,filter(\(E m2 _ _)->m2==m) contientArticles)) magasins
有什么想法吗?
编辑:
stty raw -echo
找到我想要的答案。
答案 0 :(得分:0)
disponible::[Article]->Stock->[(Magasin,Float)]
disponible articles stock = map(\(m,ls)->(m,sum $ map (\(E _ _ p)->p) ls)) $ filter ((==length articles).length.snd) magasinsArticles
where contientArticles = (filter (\(E _ a _)->a`elem`articles) stock)
magasins = foldl (\acc e-> if e`elem`acc then acc else (e:acc)) [] $ map (\(E m _ _)->m) contientArticles
magasinsArticles = map (\m->(m,filter(\(E m2 _ _)->m2==m) contientArticles)) magasins