Created
June 7, 2023 13:05
-
-
Save exarkun/1e84491d1e3da145e571ba310e7c6245 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
module Main where | |
import System.Environment (getArgs) | |
data A = A deriving Show | |
data B = B deriving Show | |
parseA :: String -> Maybe A | |
parseA "A" = Just A | |
parseA _ = Nothing | |
parseB :: String -> Maybe B | |
parseB "B" = Just B | |
parseB _ = Nothing | |
data AorB = ItsA A | ItsB B deriving Show | |
parseAorB :: String -> Maybe AorB | |
parseAorB s = case parseA s of | |
Just a -> Just $ ItsA a | |
Nothing -> case parseB s of | |
Just b -> Just $ ItsB b | |
Nothing -> Nothing | |
concatA :: A -> String -> String | |
concatA A = ('A':) | |
concatB :: B -> String -> String | |
concatB B = ('A':) | |
main :: IO () | |
main = do | |
[s] <- getArgs | |
case parseAorB s of | |
Nothing -> print "Sorry" | |
Just x -> print x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment