这是一个购物车的例子,大家感受评论下。
来自原文
import List exposing (..)
cart = []
item product quantity = { product = product, qty = quantity }
product name price = { name = name, price = price }
add cart product =
if isEmpty (filter (\item -> item.product == product) cart)
then append cart [item product 1]
else cart
subtotal cart = -- we want to calculate cart subtotal
sum (map (\item -> item.product.price * toFloat item.qty) cart)