Haskell 如何组合返回Bool的函数
有没有办法将这些函数组合在一起Haskell 如何组合返回Bool的函数,haskell,Haskell,有没有办法将这些函数组合在一起 data Patient = Patient { name :: Name, sex :: Sex, age :: Int, height :: Int, weight :: Int, bloodType :: BloodType } canDonate :: BloodType -> BloodType -> Bool canDonateTo :: Patient -> Patient -&g
data Patient = Patient
{ name :: Name,
sex :: Sex,
age :: Int,
height :: Int,
weight :: Int,
bloodType :: BloodType
}
canDonate :: BloodType -> BloodType -> Bool
canDonateTo :: Patient -> Patient -> Bool
目前我只是手动应用它们
canDonateTo :: Patient -> Patient -> Bool
canDonateTo x y = canDonate (bloodType x) (bloodType y)
但是,我想知道是否有更好的方法。使用:
(基本上,您的方法只是在上内联了的定义,可以定义为
on f g x y = f (g x) (g y)
)我更喜欢你的方式,而不是Data.Function.on
。
on f g x y = f (g x) (g y)