on master help sign in
Switch to using liftM functions in binary instances
commitd7a266b7a2360a0f4739f656153b69d7602f029e authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 30 Mar 2017, 17:23 (10 years ago) parent44cc85e
1 file changed+30−29
src/AST/Expression/Optimized.hs+30−29
src/AST/Expression/Optimized.hs+30−29
@@ -8,6 +8,7 @@ module AST.Expression.Optimized
88 where
99
1010
11+import Control.Monad (liftM, liftM2, liftM3, liftM4)
1112import Data.Binary
1213import qualified Data.Set as Set
1314import Data.Text (Text)
@@ -99,7 +100,7 @@ data Choice
99100
100101instance Binary Decl where
101102 get =
102− Decl <$> get <*> get <*> get
103+ liftM3 Decl get get get
103104
104105 put (Decl deps fx body) =
105106 put deps >> put fx >> put body
@@ -126,29 +127,29 @@ instance Binary Expr where
126127 get =
127128 do word <- getWord8
128129 case word of
129− 0 -> Literal <$> get
130− 1 -> VarLocal <$> get
131− 2 -> VarGlobal <$> get <*> get
132− 3 -> List <$> get
133− 4 -> Binop <$> get <*> get <*> get <*> get
134− 5 -> Function <$> get <*> get
135− 6 -> Call <$> get <*> get
136− 7 -> TailCall <$> get <*> get <*> get
137− 8 -> If <$> get <*> get
138− 9 -> Let <$> get <*> get
139− 10 -> Case <$> get <*> get <*> get
140− 11 -> Ctor <$> get <*> get
141− 12 -> CtorAccess <$> get <*> get
142− 13 -> Access <$> get <*> get
143− 14 -> Update <$> get <*> get
144− 15 -> Record <$> get
145− 16 -> Cmd <$> get <*> get
146− 17 -> Sub <$> get <*> get
147− 18 -> OutgoingPort <$> get <*> get
148− 19 -> IncomingPort <$> get <*> get
149− 20 -> Program <$> get <*> get
150− 21 -> GLShader <$> get
151− 22 -> Crash <$> get <*> get <*> get
130+ 0 -> liftM Literal get
131+ 1 -> liftM VarLocal get
132+ 2 -> liftM2 VarGlobal get get
133+ 3 -> liftM List get
134+ 4 -> liftM4 Binop get get get get
135+ 5 -> liftM2 Function get get
136+ 6 -> liftM2 Call get get
137+ 7 -> liftM3 TailCall get get get
138+ 8 -> liftM2 If get get
139+ 9 -> liftM2 Let get get
140+ 10 -> liftM3 Case get get get
141+ 11 -> liftM2 Ctor get get
142+ 12 -> liftM2 CtorAccess get get
143+ 13 -> liftM2 Access get get
144+ 14 -> liftM2 Update get get
145+ 15 -> liftM Record get
146+ 16 -> liftM2 Cmd get get
147+ 17 -> liftM2 Sub get get
148+ 18 -> liftM2 OutgoingPort get get
149+ 19 -> liftM2 IncomingPort get get
150+ 20 -> liftM2 Program get get
151+ 21 -> liftM GLShader get
152+ 22 -> liftM3 Crash get get get
152153 _ -> error "problem getting Opt.Expr binary"
153154
154155 put expr =
@@ -182,9 +183,9 @@ instance (Binary a) => Binary (Decider a) where
182183 get =
183184 do word <- getWord8
184185 case word of
185− 0 -> Leaf <$> get
186− 1 -> Chain <$> get <*> get <*> get
187− 2 -> FanOut <$> get <*> get <*> get
186+ 0 -> liftM Leaf get
187+ 1 -> liftM3 Chain get get get
188+ 2 -> liftM3 FanOut get get get
188189 _ -> error "problem getting Opt.Decider binary"
189190
190191 put decider =
@@ -215,7 +216,7 @@ instance Binary Choice where
215216 get =
216217 do word <- getWord8
217218 case word of
218− 0 -> Inline <$> get
219− 1 -> Jump <$> get
219+ 0 -> liftM Inline get
220+ 1 -> liftM Jump get
220221 _ -> error "problem getting Opt.Choice binary"
221222