Last active
November 16, 2017 17:32
-
-
Save denisshevchenko/51dddf63d90aee7fe2b032ab59fbd1cc 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
data Door = Door { | |
width :: Width | |
, height :: Height | |
, material :: Material | |
} | |
getHeightOfTheDoor :: House -> NumberOfDoor -> Maybe Height | |
getHeightOfTheDoor (House _ [] _) _ = Nothing :: Maybe Height | |
getHeightOfTheDoor (House _ doors _) numberOfDoor = | |
if numberOfDoor < 1 | |
then Nothing :: Maybe Height | |
else | |
if numberOfDoor > quantityOfDoors | |
then Nothing :: Maybe Height | |
else | |
let ourDoor = doors !! (numberOfDoor - 1) | |
in Just (height ourDoor) :: Maybe Height | |
where | |
quantityOfDoors = length doors | |
main :: IO () | |
main = | |
case heightOfOurDoor of | |
Nothing -> значит что-то пошло не так, и высоту двери получить не удалось | |
Just ourHeight -> print ourHeight | |
where | |
heightOfOurDoor :: Maybe Height | |
heightOfOurDoor = getHeightOfTheDoor ourHouse 2 | |
ourHouse = House ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment