on master help sign in
Get rid of either-unwrap dependency and use fewer non-total library functions
b1bca38Evan Czaplicki
Elm.cabal−2
@@ -87,7 +87,6 @@ Library
87 cmdargs,
87 cmdargs,
88 containers >= 0.3,
88 containers >= 0.3,
89 directory,
89 directory,
90− either-unwrap,
91 filepath,
90 filepath,
92 indents,
91 indents,
93 language-ecmascript >=0.15 && < 1.0,
92 language-ecmascript >=0.15 && < 1.0,
@@ -159,7 +158,6 @@ Executable elm
159 containers >= 0.3,
158 containers >= 0.3,
160 directory,
159 directory,
161 filepath,
160 filepath,
162− either-unwrap,
163 indents,
161 indents,
164 language-ecmascript >=0.15 && < 1.0,
162 language-ecmascript >=0.15 && < 1.0,
165 mtl >= 2,
163 mtl >= 2,
compiler/Metadata/Prelude.hs+15−13
@@ -11,7 +11,6 @@ import System.IO.Unsafe (unsafePerformIO)
11import SourceSyntax.Module
11import SourceSyntax.Module
12import qualified Data.Binary as Binary
12import qualified Data.Binary as Binary
13import qualified Data.ByteString.Lazy as BS
13import qualified Data.ByteString.Lazy as BS
14−import Data.Either.Unwrap (fromRight)
15
14
16import qualified InterfaceSerialization as IS
15import qualified InterfaceSerialization as IS
17
16
@@ -50,22 +49,23 @@ safeReadDocs name =
50
49
51firstModuleInterface :: Interfaces -> Either String (String, ModuleInterface)
50firstModuleInterface :: Interfaces -> Either String (String, ModuleInterface)
52firstModuleInterface interfaces =
51firstModuleInterface interfaces =
53− if Map.null interfaces then
52+ case Map.toList interfaces of
54− Left "No interfaces found in serialized Prelude!"
53+ [] -> Left "No interfaces found in serialized Prelude!"
55− else
54+ iface:_ -> Right iface
56− Right $ head $ Map.toList interfaces
57
55
58readDocs :: FilePath -> IO Interfaces
56readDocs :: FilePath -> IO Interfaces
59readDocs filePath = do
57readDocs filePath = do
60 bytes <- IS.loadInterface filePath
58 bytes <- IS.loadInterface filePath
61− let interfaces = bytes >>= IS.interfaceDecode filePath
59+ let interfaces = IS.interfaceDecode filePath =<< bytes
62
60
63− -- Although every ModuleInterface that is deserialized in this collection
61+ -- Although every ModuleInterface that is deserialized in this collection
64− -- contains the compiler version, we only check the first ModuleInterface
62+ -- contains the compiler version, we only check the first ModuleInterface
65− -- since it doesn't make sense that different modules in Prelude would have
63+ -- since it doesn't make sense that different modules in Prelude would
66− -- been compiled by different compiler versions.
64+ -- have been compiled by different compiler versions.
67− case interfaces >>= firstModuleInterface >>= IS.validVersion filePath of
65+ isValid = IS.validVersion filePath =<< firstModuleInterface =<< interfaces
66+
67+ case (interfaces, isValid) of
68− Left err -> do
68+ (_, Left err) -> do
69 hPutStrLn stderr err
69 hPutStrLn stderr err
70 exitFailure
70 exitFailure
71
71
@@ -73,4 +73,6 @@ readDocs filePath = do
73 -- returns a Right value. The toList/fromList is necessary because of a
73 -- returns a Right value. The toList/fromList is necessary because of a
74 -- problem with looking up keys in the Map after deserialization. Example
74 -- problem with looking up keys in the Map after deserialization. Example
75 -- at https://gist.github.com/jsl/7294493.
75 -- at https://gist.github.com/jsl/7294493.
76+ -- TODO: try switching to Data.ByteString.Lazy.Char8
77+ (Right ifaces, _) ->
76− Right _ -> return $ Map.fromList $ Map.toList $ fromRight interfaces
78+ return $ Map.fromList $ Map.toList ifaces