Skip to content

Instantly share code, notes, and snippets.

@totetmatt
Last active December 19, 2019 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save totetmatt/481087b880445471b7d87f3c0c0accad to your computer and use it in GitHub Desktop.
Save totetmatt/481087b880445471b7d87f3c0c0accad to your computer and use it in GitHub Desktop.
ccc-2019.hs
-- 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