Skip to content

Instantly share code, notes, and snippets.

@bchase
Last active May 16, 2019 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bchase/73135dbdcd15fff9601c5376bcd64f3d to your computer and use it in GitHub Desktop.
Save bchase/73135dbdcd15fff9601c5376bcd64f3d to your computer and use it in GitHub Desktop.
-- 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