how to compose functions that return Bool together

Asked By: Anonymous

Is there a way to compose these functions together?

data Patient = Patient
  { name :: Name,
    sex :: Sex,
    age :: Int,
    height :: Int,
    weight :: Int,
    bloodType :: BloodType

canDonate :: BloodType -> BloodType -> Bool

canDonateTo :: Patient -> Patient -> Bool

Currently I’m just manually applying them

canDonateTo :: Patient -> Patient -> Bool
canDonateTo x y = canDonate (bloodType x) (bloodType y)

However, I’m wondering if there is a better way to do it.


Answered By: Anonymous

Use Data.Function.on:

import Data.Function (on)

canDonateTo = canDonate `on` bloodType

(Basically, your approach just inlined the definition of on, which could be defined as

on f g x y = f (g x) (g y)


techinplanet staff

techinplanet staff

Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno