@@ -32,7 +32,7 @@ import System.Directory
32
32
( getCurrentDirectory , doesDirectoryExist , doesFileExist , copyFile
33
33
, getDirectoryContents , createDirectoryIfMissing )
34
34
import System.FilePath
35
- ( (</>) , (<.>) , takeBaseName , equalFilePath )
35
+ ( (</>) , (<.>) , takeBaseName , takeExtension , equalFilePath )
36
36
import Data.Time
37
37
( getCurrentTime , utcToLocalTime , toGregorian , localDay , getCurrentTimeZone )
38
38
@@ -831,7 +831,7 @@ writeMainHs flags mainPath = do
831
831
exists <- doesFileExist mainFullPath
832
832
unless exists $ do
833
833
message flags $ " Generating " ++ mainPath ++ " ..."
834
- writeFileSafe flags mainFullPath mainHs
834
+ writeFileSafe flags mainFullPath ( mainHs flags)
835
835
836
836
-- | Check that a main file exists.
837
837
hasMainHs :: InitFlags -> Bool
@@ -840,14 +840,23 @@ hasMainHs flags = case mainIs flags of
840
840
|| packageType flags == Flag LibraryAndExecutable )
841
841
_ -> False
842
842
843
- -- | Default Main.hs file. Used when no Main.hs exists.
844
- mainHs :: String
845
- mainHs = unlines
843
+ -- | Default Main.(l) hs file. Used when no Main.(l) hs exists.
844
+ mainHs :: InitFlags -> String
845
+ mainHs flags = ( unlines . map prependPrefix)
846
846
[ " module Main where"
847
847
, " "
848
848
, " main :: IO ()"
849
849
, " main = putStrLn \" Hello, Haskell!\" "
850
850
]
851
+ where
852
+ prependPrefix " " = " "
853
+ prependPrefix line
854
+ | isLiterate = " > " ++ line
855
+ | otherwise = line
856
+ isLiterate = case mainIs flags of
857
+ Flag mainPath -> takeExtension mainPath == " .lhs"
858
+ _ -> False
859
+
851
860
852
861
-- | Move an existing file, if there is one, and the overwrite flag is
853
862
-- not set.
0 commit comments