@@ -11,7 +11,6 @@ import System.IO.Unsafe (unsafePerformIO)
1111import SourceSyntax.Module
1212import qualified Data.Binary as Binary
1313import qualified Data.ByteString.Lazy as BS
14−import Data.Either.Unwrap (fromRight)
1514
1615import qualified InterfaceSerialization as IS
1716
@@ -50,22 +49,23 @@ safeReadDocs name =
5049
5150firstModuleInterface :: Interfaces -> Either String (String, ModuleInterface)
5251firstModuleInterface interfaces =
53− if Map.null interfaces then
54− Left "No interfaces found in serialized Prelude!"
55− else
56− Right $ head $ Map.toList interfaces
52+ case Map.toList interfaces of
53+ [] -> Left "No interfaces found in serialized Prelude!"
54+ iface:_ -> Right iface
5755
5856readDocs :: FilePath -> IO Interfaces
5957readDocs filePath = do
6058 bytes <- IS.loadInterface filePath
61− let interfaces = bytes >>= IS.interfaceDecode filePath
59+ let interfaces = IS.interfaceDecode filePath =<< bytes
6260
63− -- Although every ModuleInterface that is deserialized in this collection
64− -- contains the compiler version, we only check the first ModuleInterface
65− -- since it doesn't make sense that different modules in Prelude would have
66− -- been compiled by different compiler versions.
67− case interfaces >>= firstModuleInterface >>= IS.validVersion filePath of
68− Left err -> do
61+ -- Although every ModuleInterface that is deserialized in this collection
62+ -- contains the compiler version, we only check the first ModuleInterface
63+ -- since it doesn't make sense that different modules in Prelude would
64+ -- have been compiled by different compiler versions.
65+ isValid = IS.validVersion filePath =<< firstModuleInterface =<< interfaces
66+
67+ case (interfaces, isValid) of
68+ (_, Left err) -> do
6969 hPutStrLn stderr err
7070 exitFailure
7171
@@ -73,4 +73,6 @@ readDocs filePath = do
7373 -- returns a Right value. The toList/fromList is necessary because of a
7474 -- problem with looking up keys in the Map after deserialization. Example
7575 -- at https://gist.github.com/jsl/7294493.
76− Right _ -> return $ Map.fromList $ Map.toList $ fromRight interfaces
76+ -- TODO: try switching to Data.ByteString.Lazy.Char8
77+ (Right ifaces, _) ->
78+ return $ Map.fromList $ Map.toList ifaces