Skip to content

Commit eefdcc4

Browse files
committed
Type: Infer: InferState: rm newtype accessor
1 parent 38ac1fe commit eefdcc4

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/Nix/Type/Infer.hs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff 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
156164
initInfer :: InferState
157-
initInfer = InferState { count = 0 }
165+
initInfer = InferState 0
158166

159167
letters :: [String]
160168
letters =
@@ -168,8 +176,8 @@ freshTVar :: MonadState InferState m => m TVar
168176
freshTVar =
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

174182
fresh :: MonadState InferState m => m Type
175183
fresh = TVar <$> freshTVar

0 commit comments

Comments
 (0)