on master help sign in
Make Binary serialization code nicer
commit5c509f2f1e1d07c281dd17a650949edd9d90cf91 authorEvan Czaplicki <info@elm-lang.org> dateThu 2 Jan 2014, 17:42 (13 years ago) parent662fd76
1 file changed+9−12
compiler/SourceSyntax/Module.hs+9−12
compiler/SourceSyntax/Module.hs+9−12
@@ -10,7 +10,6 @@ import SourceSyntax.Expression (LExpr)
1010import SourceSyntax.Declaration
1111import SourceSyntax.Type
1212import System.FilePath (joinPath)
13−import Control.Monad (liftM)
1413
1514import qualified Elm.Internal.Version as Version
1615
@@ -25,20 +24,18 @@ data ImportMethod = As String | Importing [String] | Hiding [String]
2524 deriving (Eq, Ord, Show)
2625
2726instance Binary ImportMethod where
28− put (As s) = do put (0 :: Word8)
29− put s
30−
31− put (Importing ss) = do put (1 :: Word8)
32− put ss
33−
34− put (Hiding ss) = do put (2 :: Word8)
35− put ss
27+ put method =
28+ let put' n info = putWord8 n >> put info in
29+ case method of
30+ As s -> put' 0 s
31+ Importing ss -> put' 1 ss
32+ Hiding ss -> put' 2 ss
3633
3734 get = do tag <- getWord8
3835 case tag of
39− 0 -> liftM As get
40− 1 -> liftM Importing get
41− 2 -> liftM Hiding get
36+ 0 -> As <$> get
37+ 1 -> Importing <$> get
38+ 2 -> Hiding <$> get
4239 _ -> error "Error reading valid ImportMethod type from serialized string"
4340
4441data MetadataModule t v = MetadataModule {