Skip to content

Instantly share code, notes, and snippets.

@denisshevchenko
Last active November 16, 2017 17:32
Show Gist options
  • Save denisshevchenko/51dddf63d90aee7fe2b032ab59fbd1cc to your computer and use it in GitHub Desktop.
Save denisshevchenko/51dddf63d90aee7fe2b032ab59fbd1cc to your computer and use it in GitHub Desktop.
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