File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -149,12 +149,20 @@ instance Monoid InferError where
149149
150150-- * @InferState@: inference state
151151
152- -- | Inference state
153- newtype InferState = InferState { count :: Int }
152+ -- | Inference state (stage).
153+ newtype InferState = InferState Int
154+ deriving
155+ (Eq , Num , Enum , Ord )
156+
157+ instance Semigroup InferState where
158+ (<>) a b = a + b
159+
160+ instance Monoid InferState where
161+ mempty = 0
154162
155163-- | Initial inference state
156164initInfer :: InferState
157- initInfer = InferState { count = 0 }
165+ initInfer = InferState 0
158166
159167letters :: [String ]
160168letters =
@@ -168,8 +176,8 @@ freshTVar :: MonadState InferState m => m TVar
168176freshTVar =
169177 do
170178 s <- get
171- put s { count = count s + 1 }
172- pure $ TV $ toText $ letters !! count s
179+ put $ succ s
180+ pure $ TV $ toText $ letters !! coerce s
173181
174182fresh :: MonadState InferState m => m Type
175183fresh = TVar <$> freshTVar
You can’t perform that action at this time.
0 commit comments