type History = [Purchase Item]
[Purchase "Alex" [Item "Milk" 2 0.49, Item "Coke" 1 1.99],
        Purchase "Bobby" [Item "Bread" 1 0.99]]

如何使用此 Contract 实现功能:

getByName: String -> History -> History

因此,getByName应返回包含由给定名称购买的所有项目的历史记录 . 所以

getByName [Purchase "Alex" [Item "Milk" 2 0.49, Item "Coke" 1 1.99],
            Purchase "Bobby" [Item "Bread" 1 0.99]]" = [Purchase "Alex" [Item "Milk" 2 0.49, Item "Coke" 1 1.99]]

我知道我必须使用列表理解和过滤功能,但我不知道如何,因为我不知道如何访问“历史”类型的“购买”来获取买家名称 .

这是我的购买数据

data Purchase a = Purchase { buyer :: String
                 , items :: [a]
                 } deriving (Show, Eq, Read)

和我的物品数据

data Item = Item { name :: String
                 , quantity :: Int
                 , price :: Float
                 } deriving (Show, Eq, Read)

有什么建议?