You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

28 lines
788 B

module Person where
validateLength :: Int -> String -> Maybe String
validateLength maxLen s =
if (length s) > maxLen
then Nothing
else Just s
newtype Name = Name String deriving (Eq, Show)
newtype Address = Address String deriving (Eq, Show)
mkName :: String -> Maybe Name
mkName s = fmap Name $ validateLength 25 s
mkAddress :: String -> Maybe Address
mkAddress a = fmap Address $ validateLength 100 a
data Person = Person Name Address deriving (Eq, Show)
mkPerson :: String -> String -> Maybe Person
-- mkPerson n a =
-- case mkName n of
-- Nothing -> Nothing
-- Just n' ->
-- case mkAddress a of
-- Nothing -> Nothing
-- Just a' -> Just $ Person n' a'
mkPerson n a = Person <$> mkName n <*> mkAddress a