Skip to content

Instantly share code, notes, and snippets.

@wavebeem
Created August 7, 2015 01:45
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 wavebeem/294674365091a5baa35f to your computer and use it in GitHub Desktop.
Save wavebeem/294674365091a5baa35f to your computer and use it in GitHub Desktop.
-- Also note, it seems people generally reach for positional types unless the data has many fields.
-- data BTNode t = BTNode t (BTNode t) (BTNode t) | BTNil
-- as opposed to:
-- data BTNode t = BTNode { data :: t, left :: BTNode, right :: BTnode } | BTNil
data Car2 = Car2 { make :: Maybe String } deriving (Show)
-- Haskell automatically makes a function in this scope:
-- make :: Car2 -> Maybe String
-- So you can just say `make c1` to get the make of the Car2 called `c1`.
carMake :: Car2 -> Maybe String
carMake (Car2 x) = x
c1 = Car2 Nothing
definitelyTrue = carMake c1 == make c1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment