Last active
December 19, 2019 07:40
-
-
Save totetmatt/481087b880445471b7d87f3c0c0accad to your computer and use it in GitHub Desktop.
ccc-2019.hs
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
-- Compilation : ghc ccc2019.hs -o regex | |
-- Usage : ./regex "a*b" "aaab" | |
import System.Environment | |
import System.Exit | |
main :: IO () | |
eq a b | a == '.' = True | |
| otherwise = a == b | |
match (a:'*':xa) (b:xb) | eq a b = match (a:'*':xa) xb | |
| otherwise = match xa (b:xb) | |
match (a:'*':xa) [] = match xa [] | |
match (a:xa) (b:xb) | eq a b = match xa xb | |
| otherwise = False | |
match [] [] = True | |
match _ _ = False | |
-- Ext return code to be pipe-able on bash | |
exit True = exitWith ExitSuccess | |
exit False = exitWith (ExitFailure 1) | |
main = do | |
args <- getArgs | |
let result = match (head args) (last args) | |
print result | |
exit result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment