Created
December 4, 2018 21:05
-
-
Save ordnungswidrig/dfbb5020c52b16e3a74406284015cdc5 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
{-# 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