diff --git a/lab05/maybeEither.hs b/lab05/maybeEither.hs new file mode 100644 index 0000000..0e9a2c2 --- /dev/null +++ b/lab05/maybeEither.hs @@ -0,0 +1,25 @@ +getMax :: [Int] -> Maybe Int +getMax [] = Nothing +getMax x = Just (maximum x) + +reciprocal :: (Eq a, Fractional a) => a -> Maybe a +reciprocal 0 = Nothing +reciprocal x = Just (1/x) + +rectangleArea :: Int -> Int -> Either String Int +rectangleArea x y + | x < 0 = Left "Width is not positive" + | y < 0 = Left "Height is not positive" + | otherwise = Right (x * y) + +main :: IO () +main = do + print $ getMax [] + print $ getMax [99,12,37] + print $ getMax [-99,-12,-37] + print $ reciprocal 4 + print $ reciprocal 2 + print $ reciprocal 0 + print $ rectangleArea 5 10 + print $ rectangleArea (-5) 10 + print $ rectangleArea 5 (-10) diff --git a/lab05/maybeEither.signed.zip b/lab05/maybeEither.signed.zip new file mode 100644 index 0000000..a3e2cba Binary files /dev/null and b/lab05/maybeEither.signed.zip differ