From 3a7f7a568d04bb16078246674a29f48468eba940 Mon Sep 17 00:00:00 2001 From: Mario Pastorelli Date: Sun, 18 Aug 2013 23:16:23 +0200 Subject: [PATCH] fix #50 --- src/System/Console/Hawk.hs | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/System/Console/Hawk.hs b/src/System/Console/Hawk.hs index 66461c0..07527d6 100644 --- a/src/System/Console/Hawk.hs +++ b/src/System/Console/Hawk.hs @@ -39,10 +39,6 @@ import System.Console.Hawk.Config import System.Console.Hawk.Options --- missing error handling!! -readImportsFromFile :: FilePath -> IO [(String,Maybe String)] -readImportsFromFile fp = P.read <$> IO.readFile fp - initInterpreter :: (String, String) -- ^ config file and module nme -> Maybe FilePath -> InterpreterT IO () @@ -55,18 +51,19 @@ initInterpreter config moduleFile = do -- load the config file loadModules [P.fst config] - let modules = (P.snd config,Nothing):defaultModules - - maybe (setImportsQ modules) - (setImportsQFromFile modules) - moduleFile - where - setImportsQFromFile :: [(String,Maybe String)] - -> FilePath - -> InterpreterT IO () - setImportsQFromFile requiredImports confFile = do - imports <- lift (readImportsFromFile confFile) - setImportsQ $ imports ++ requiredImports + -- load the config module plus representable + let requiredModules = (P.snd config,Nothing):defaultModules + userModules <- lift $ maybe (return []) loadFromFile moduleFile + + let modules = requiredModules ++ userModules + + let modulesWithPrelude = if "Prelude" `L.notElem` fmap P.fst modules + then ("Prelude",Nothing):modules + else modules + + setImportsQ modulesWithPrelude + where loadFromFile :: FilePath -> IO [(String,Maybe String)] + loadFromFile fp = P.read <$> IO.readFile fp printErrors :: InterpreterError -> IO () printErrors e = case e of