Created
April 5, 2020 15:17
-
-
Save randomshinichi/dfb2accfdc10da40cdba79162e283327 to your computer and use it in GitHub Desktop.
This file contains 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 OverloadedStrings #-} | |
tupleFromInputString :: String -> Maybe (String, String, Integer) | |
tupleFromInputString input = | |
if length stringComponents /= 3 | |
then Nothing | |
else Just (stringComponents !! 0, stringComponents !! 1, age) | |
where | |
stringComponents = words input | |
age = (read (stringComponents !! 2) :: Integer) | |
data Person = Person { | |
firstName :: String, | |
lastName :: String, | |
age :: Integer | |
} deriving (Show) | |
personFromTuple :: (String, String, Integer) -> Person | |
personFromTuple (fName, lName, age) = Person fName lName age | |
convertTuple :: Maybe (String, String, Integer) -> Maybe Person | |
convertTuple Nothing = Nothing | |
convertTuple (Just t) = Just (personFromTuple t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment