Skip to content

Instantly share code, notes, and snippets.

@ordnungswidrig
Created December 4, 2018 21:05
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 ordnungswidrig/dfbb5020c52b16e3a74406284015cdc5 to your computer and use it in GitHub Desktop.
Save ordnungswidrig/dfbb5020c52b16e3a74406284015cdc5 to your computer and use it in GitHub Desktop.
{-# LANGUAGE DuplicateRecordFields #-}
-- how to resolve the duplication in CreateUser, BasicUser and UpdateUser
-- without changing everything to `Maybe String`?
data Address = Address { street :: String
, zip :: String
, city :: String
, state :: String
} deriving (Show)
data CreateUser = CreateUser { first :: String
, last :: String
, address :: Address
} deriving (Show)
data UpdateUser = UpdateUser { id :: Int
, first :: Maybe String
, last :: Maybe String
, address :: Maybe Address
} deriving (Show)
data BasicUser = BasicUser { id :: Int
, first :: String
, last :: String
} deriving (Show)
createUser :: CreateUser -> Int
createUser (CreateUser { first = _, last = _, address = _}) = 99
updateUser :: UpdateUser -> Bool
updateUser (UpdateUser { id = _, first = _, last = _, address = _}) = True
findBasicUser :: Int -> BasicUser
findBasicUser id = BasicUser{id = id, first = "Joe", last = "Smith"}
main :: IO ()
main = putStrLn "hello, world"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment