|
definition: |
writeMainExpFile :: ReplState -> [String] -> Maybe String -> String -> IO ()
writeMainExpFile rst imports mtype exp =
writeFile (mainExpFile rst) $ unlines $
[noMissingSigs, "module " ++ mainExpMod rst ++ " where"] ++
map ("import " ++) allImports ++
maybe [] (\ts -> ["main :: " ++ ts]) mtype ++
["main = " ++ concatMap (++ " in\n ") (letBinds rst)
++ qualifyMain (strip exp)]
where
allImports = filter (/="Prelude") . nub $ currMod rst : addMods rst ++ imports
noMissingSigs = "{-# OPTIONS_FRONTEND -W no-missing-signatures #-}"
-- simple hack to avoid name conflict with "main":
-- (better solution: pretty print parsed main expression with qualification)
qualifyMain :: String -> String
qualifyMain [] = []
qualifyMain s@(x:xs)
| "main" `isPrefixOf` s = case drop 3 xs of
[] -> currMod rst ++ ".main"
c:_ | not (isAlphaNum c)
-> currMod rst ++ ".main" ++ drop 3 xs
_ -> x : qualifyMain xs
| isAlphaNum x = let (prev, next) = span isAlphaNum xs
in x : prev ++ qualifyMain next
| otherwise = x : qualifyMain xs
|
|
demand: |
no demanded arguments |
|
deterministic: |
deterministic operation |
|
documentation: |
write the file with the main exp where necessary imports and possibly a type string is provided: |
|
failfree: |
(_, _, _, _) |
|
indeterministic: |
referentially transparent operation |
|
infix: |
no fixity defined |
|
iotype: |
{(_,_,_,_) |-> _}
|
|
name: |
writeMainExpFile |
|
precedence: |
no precedence defined |
|
result-values: |
_ |
|
signature: |
REPL.State.ReplState -> [String] -> Prelude.Maybe String -> String -> Prelude.IO () |
|
solution-complete: |
operation might suspend on free variables |
|
terminating: |
possibly non-terminating |
|
totally-defined: |
possibly non-reducible on same data term |