Running program

maybeEither.hs:

Nothing
Just 99
Just (-12)
Just 0.25
Just 0.5
Nothing
Right 50
Left "Width is not positive"
Left "Height is not positive"
pass

Submitted files

maybeEither.hs:

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)

Score

1/1

2026-02-22T05:28:17Z