如何查询不吃馅饼的人的清单?

时间:2017-03-22 15:20:48

标签: haskell

我正在学习Haskell,我尝试实施以下练习:

  

经过漫长的徒步旅行后,每个人都可以在小屋内要求最多三个馅饼。存储名称和馅饼类型选择列表。

     

示例:

didnteat hikers
     

创建一个函数来确定谁没有要求任何一块蛋糕!

     

输入:["Tamás", "Vera"]
  输出:var HID = require('node-hid'); var devices = HID.devices();

但是,我真的不知道从哪里开始。有人可以帮我提一些提示吗?

1 个答案:

答案 0 :(得分:1)

hikers = [ ("Andras", ["poppy", "cherry", "apple"])
         , ("Joli", ["cottage cheese"])
         , ("Anna", ["apple", "apple"])
         , ("Tamás", [])
         , ("Mari", ["apple", "cherry"])
         , ("Vera", []) ]

-- Since you only want name from the tuple, 
-- then transform from tuple to only the first thing in the tuple (name) using fst
namesOfHikersWitoutPie = map fst hikersWithoutPie

-- Apply the predicate with a filter, so you only get the hikers with empty list
hikersWithoutPie = filter hasNoPie hikers

--Predicate that pattern-matches for empty lists, 
--using '_' since we don't care about the values
hasNoPie (_, []) = True
hasNoPie (_, _) = False
相关问题