on 727d708 help sign in
elk/compiler/Metadata/Prelude.hs
51 lines 1.9 kB history raw
1module Metadata.Prelude (interfaces, add) where
3import qualified Data.Map as Map
4import qualified Control.Exception as E
5import qualified Paths_Elm as Path
6import System.Directory
7import System.Exit
8import System.FilePath
9import System.IO.Unsafe (unsafePerformIO)
10import SourceSyntax.Module
11import Data.Binary
14add :: Module t v -> Module t v
15add (Module name exs ims stmts) = Module name exs (customIms ++ ims) stmts
16 where
17 customIms = concatMap addModule prelude
19 addModule (n, method) = case lookup n ims of
20 Nothing -> [(n, method)]
21 Just (As m) -> [(n, method)]
22 Just _ -> []
24prelude :: [(String, ImportMethod)]
25prelude = text : map (\n -> (n, Hiding [])) modules
26 where
27 text = ("Text", Hiding ["link", "color", "height"])
28 modules = [ "Prelude", "Signal", "List", "Maybe", "Time"
29 , "Graphics.Element", "Color", "Graphics.Collage" ]
31{-# NOINLINE interfaces #-}
32interfaces :: Interfaces
33interfaces =
34 unsafePerformIO (safeReadDocs =<< Path.getDataFileName "interfaces.data")
36safeReadDocs :: FilePath -> IO Interfaces
37safeReadDocs name =
38 E.catch (readDocs name) $ \err -> do
39 putStrLn $ unlines [ "Error reading types for standard library!"
40 , " " ++ show (err :: IOError)
41 , "The file should be located here: " ++ name
42 , " If you are using a stable version of Elm,"
43 , " please report an issue at github.com/evancz/Elm"
44 , " and specify your versions of Elm and your OS" ]
45 exitFailure
47readDocs :: FilePath -> IO Interfaces
48readDocs name = do
49 exists <- doesFileExist name
50 if exists then decodeFile name
51 else ioError . userError $ "File Not Found"