Skip to content

Instantly share code, notes, and snippets.

@randomshinichi
Created April 5, 2020 15:17
Show Gist options
  • Save randomshinichi/dfb2accfdc10da40cdba79162e283327 to your computer and use it in GitHub Desktop.
Save randomshinichi/dfb2accfdc10da40cdba79162e283327 to your computer and use it in GitHub Desktop.
{-# 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