Skip to content

Instantly share code, notes, and snippets.

@skahack
Created September 12, 2011 09:25
Show Gist options
  • Save skahack/1210913 to your computer and use it in GitHub Desktop.
Save skahack/1210913 to your computer and use it in GitHub Desktop.
Named Fields
module Main where
data Option =
Option
{ option1 :: String
, option2 :: Maybe String
, option3 :: Maybe String
} deriving (Show)
opt = Option
{ option1 = "Option1"
, option2 = Nothing
, option3 = Just "Option3"
}
getOption3 :: Option -> String
getOption3 (Option _ _ (Nothing)) = ""
getOption3 (Option _ _ (Just x)) = x
getOption2 :: Option -> String
getOption2 (Option {option2 = Nothing}) = ""
getOption2 (Option {option2 = Just x}) = x
main = putStrLn $ show $ getOption2 opt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment