Skip to content

Instantly share code, notes, and snippets.

@denisshevchenko
Last active November 24, 2017 15:51
Show Gist options
  • Save denisshevchenko/145c1ee59577f7e86fda51a28657836b to your computer and use it in GitHub Desktop.
Save denisshevchenko/145c1ee59577f7e86fda51a28657836b to your computer and use it in GitHub Desktop.
module Main where
import Lib
import Data.Text
import Data.List
data Patient = Patient Text
data Disease = Dis Text
type Diagnosis = (Patient,Disease)
data PatientError = NoDiagnosis | NoPatientWithSuchDisease
getPatientByDisease :: [Diagnosis] -> Disease -> Either PatientError Patient
getPatientByDisease [] _ = Left NoDiagnosis
getPatientByDisease diagnosis disease =
let maybeDiagnosis = Data.List.find predicate diagnosis
in case maybeDiagnosis of
Nothing -> Left NoPatientWithSuchDisease
Just (patient, _) -> Right patient
where
predicate :: Diagnosis -> Bool
predicate (_,patientDisease Text) = diseaseName == patientDiseaseName
where
(Dis diseaseName) = disease
(Dis patientDiseaseName) = patientDisease
main :: IO ()
main = print $ getPatientByDisease [(Patient "Иван", Diesease "Простуда")] (Disease "Простуда")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment