Last active
May 16, 2019 23:28
-
-
Save bchase/73135dbdcd15fff9601c5376bcd64f3d 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
-- haskell syntax, btw | |
data Maybe a | |
= Nothing | |
| Just a | |
noStringHere :: Maybe String | |
noStringHere = Nothing | |
aStringHere :: Maybe String | |
aStringHere = Just "hello, chief" | |
handlePotentialNothingness :: Maybe String -> String | |
handlePotentialNothingness mStr = | |
case mStr of | |
Nothing -> "some default string" | |
Just str -> str | |
data List a | |
= Cons a (List a) | |
| Nil | |
aList :: [a] | |
aList = [1,2,3] | |
-- [1,2,3] | |
-- 1 : 2 : 3 : [] | |
-- 1 : ( 2 : ( 3 : [] ) ) | |
-- | |
-- where `:` is pronounced "cons" | |
-- and `[]` is pronounced "nil" | |
-- | |
-- we could rewrite the above with `List`... | |
ourList :: List Int | |
ourList = Cons 1 (Cons 2 (Cons 3 Nil)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment