This file contains 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
alt2 :: Int -> Maybe Int | |
alt2 41 = Nothing | |
alt2 x = return (x + 1) |
This file contains 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
plusOne :: Int -> Maybe Int | |
plusOne x = return (x + 1) |
This file contains 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
plusOne :: Int -> Maybe Int | |
plusOne x = Just (x + 1) |
This file contains 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
applicativeEx :: Maybe Int | |
applicativeEx = (+ 1) <*> Just 42 -- Just 43 |
This file contains 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
fmapEx :: Maybe Int | |
fmapEx = fmap (Just (+ 1)) (Just 42) -- Does not compile |
This file contains 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
fmapEx :: [Int] -- A function returning a list | |
fmapEx = fmap (+ 1) [1, 2, 3] -- [2, 3, 4] |
This file contains 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
fmapEx :: Maybe Int | |
fmapEx = fmap (+ 1) Nothing -- Nothing |
This file contains 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
fmapEx :: Maybe Int -- A function returning a Maybe Int | |
fmapEx = fmap (+ 1) (Just 42) -- Just 43 |
This file contains 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
applicativeEx :: Maybe Int | |
applicativeEx = (+ 1) <$> Just 42 -- Just 43 |
This file contains 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
applicativeEx :: [Int] | |
applicativeEx = [(+ 1)] <*> [1, 2, 3] -- [2, 3, 4] |