Created
January 7, 2019 17:02
-
-
Save vvviiimmm/c76f43e1ec1faf041cd2dd9284f97145 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
-- Simple sum type with two options | |
data Maybe a = Just a | Nothing | |
-- Safe total function that never throws | |
divide :: Int -> Int -> Maybe Int | |
divide dividend divisor = if divisor == 0 then Nothing else Just (dividend / divisor) | |
-- Maybe is available in Data.Maybe module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment