Last active
November 24, 2017 15:51
-
-
Save denisshevchenko/145c1ee59577f7e86fda51a28657836b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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