具有数据类型的功能

时间:2017-04-13 03:32:54

标签: haskell

我的代码中有这些数据

data Client = aClient {name::String,alcohol::Int,friends::[Client]} deriving (Show)

我试图制作一个取决于顾客休息时间的功能,它会增加酒精抵抗力。

letgo :: Client -> Integer -> Client
letgo (aClient _ alcohol _) hours

我需要知道如何根据条件更新数据中的酒精字段。

1 个答案:

答案 0 :(得分:-1)

data Client = Client {name::String,alcohol::Int,friends::[Client]} deriving (Show)

letgo :: Client -> Integer -> Client
letgo client@(Client name alcohol friends) hours
  | sufficientRest hours = Client name (increaseResistance alcohol) friends
  | otherwise = client

sufficientRest     :: Integer -> Bool
increaseResistance :: Int -> Int