diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-02-21 23:51:29 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-02-21 23:51:29 +1100 |
commit | e25b703805a6d5b20ddcb70e406830ca8d16cd22 (patch) | |
tree | 8b54e49e2cd6a04d3f0958e8395651dbf607dc7d /fractran.hs | |
parent | 50958fc5f2aad6f72fa8b948f8fa33713beb91a1 (diff) |
Revised programming style
Diffstat (limited to 'fractran.hs')
-rw-r--r-- | fractran.hs | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/fractran.hs b/fractran.hs index 7f3946f..964a095 100644 --- a/fractran.hs +++ b/fractran.hs @@ -1,16 +1,11 @@ import System.Environment( getArgs ) import Data.Typeable -import qualified Control.Exception +import Control.Exception( ErrorCall(..), Handler(..), catches ) import Fractran.Parser import Fractran.Interpreter -data FractranException = FractranException { errString :: String } - deriving (Show, Typeable) - -instance Control.Exception.Exception FractranException - usageString :: String @@ -22,7 +17,7 @@ program :: IO () program = do args <- getArgs fileContents <- if (length args /= 1) - then Control.Exception.throw (FractranException usageString) + then error usageString else readFile (head args) case (parseFractran fileContents) of @@ -31,8 +26,6 @@ program = do -main = Control.Exception.catch program handler - where - handler :: FractranException -> IO () - handler err = putStrLn (errString err) +main = catches program + [ Handler ((\e -> putStrLn . show $ e) :: ErrorCall -> IO ()) ] |