私が持っている別の基本的な問題で再び私に。私はghciを使用しています。
私は(助けを借りて)この作業コードを作成しました:
newtype Name = Name String deriving (Show)
newtype Age = Age Int deriving (Show)
newtype Weight = Weight Int deriving (Show)
newtype Person = Person (Name, Age, Weight) deriving (Show)
isAdult :: Person -> Bool
isAdult (Person(_, Age a, _)) = a > 18
ただし、ユーザーが以前の値から人の体重を変更できるようにする、より複雑な関数 updateWeight を作成しようとすると、問題が発生します。私が間違っているところを指摘できますか?
updateWeight :: Person -> Int -> Person
updateWeight (Person(_,_,Weight w) b = (Person(_,_,w+b))