Skip to content

Instantly share code, notes, and snippets.

View teivah's full-sized avatar
🧮
Current status: teivah/majorana

Teiva Harsanyi teivah

🧮
Current status: teivah/majorana
View GitHub Profile
plusOne :: Maybe (Int -> Int)
plusOne = Just (+ 1)
plusOne :: Int -> Maybe Int
plusOne x = Just (x + 1)
plusOne :: Int -> Int
plusOne x = x + 1
plusOne :: Int -> Maybe Int
plusOne x = return (x + 1)
monadEx :: Maybe Int
monadEx = Just 42 >>= plusOne -- Just 43
plusOne :: Int -> Maybe Int
plusOne x = return (x + 1)
plusOne :: Int -> Maybe Int
plusOne x = Just (x + 1)
fmapEx :: Maybe Int -- A function returning a Maybe Int
fmapEx = fmap (+ 1) (Just 42) -- Just 43
withMonad :: Int -> String -> Maybe String
withMonad age name = do
validateAge age
s <- return (greet name)
return (greet s) -- Just "Hello Hello John"
withMonad :: Int -> String -> Maybe String
withMonad age name = do
validateAge age
return (greet name)
withMonad :: Int -> String -> Maybe String
withMonad age name = validateAge age >>= \_ -> return (greet name)