Skip to content

Commit adba949

Browse files
committed
Make some top-level function names clearer
npushl, pushl, npushr, pushr, npopl, popl, npopr, popr, fix0l, fix0r, fix2l, fix2r now all have more explanatory names.
1 parent 08949ad commit adba949

File tree

1 file changed

+86
-78
lines changed

1 file changed

+86
-78
lines changed

exposed.hs

+86-78
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ bestow2R ones twos level (S4 l1 l3 l4) = case twos of
197197
L3R lower n1 n2 n3 -> L3RL level l1 (L2RL lower n1 n2) n3
198198

199199

200-
npushl :: NLayered n Pair a ->
201-
S4 a n L0Exposed rexposure ->
202-
S4 a n L2Exposed rexposure
203-
npushl a (S4 l1 l3 l4) = case l1 of
200+
naiveInjectLeft :: NLayered n Pair a ->
201+
S4 a n L0Exposed rexposure ->
202+
S4 a n L2Exposed rexposure
203+
naiveInjectLeft a (S4 l1 l3 l4) = case l1 of
204204
L1L (LH1 l, RH1 r) m1 ->
205205
pushMU (LH2 (Pair a l), RH1 r) (S4 m1 l3 l4)
206206
L1E -> case l3 of
@@ -219,34 +219,34 @@ npushl a (S4 l1 l3 l4) = case l1 of
219219
L4E (Final5 p q r s b) -> S4 (L1L (LH1 a, RH1 b) L1E)
220220
L3E (L4E (Final2 (LN (Pair p q)) (LN (Pair r s))))
221221

222-
fix2l :: S4 a n L2Exposed rexposure ->
223-
S4 a n L0Exposed rexposure
224-
fix2l (S4 l1 l3 l4) = case l3 of
222+
fix2ExposureLeft :: S4 a n L2Exposed rexposure ->
223+
S4 a n L0Exposed rexposure
224+
fix2ExposureLeft (S4 l1 l3 l4) = case l3 of
225225
L3L (LH2 l, RH1 r) m1 m2 m3 ->
226226
bestowL l1 (LH0 (), RH1 r) $
227-
npushl (LN l) $
227+
naiveInjectLeft (LN l) $
228228
push2l m1 m2 m3 l4
229229
L3R level m1 m2 m3 -> bestowR l1 level $ case m3 of
230230
L3LL (LH2 l, RH1 r) n1 n2 n3 ->
231231
bestow2L m1 m2 (LH0 (), RH1 r) $
232-
npushl (LN l) $
232+
naiveInjectLeft (LN l) $
233233
push2l n1 n2 n3 l4
234234
L3LE -> push2r m1 m2 L3LE $ case l4 of
235235
L4 (LH2 l, r) rest ->
236-
L4 (LH0 (), r) (npushl (LN l) rest)
236+
L4 (LH0 (), r) (naiveInjectLeft (LN l) rest)
237237
L4E final -> L4E final
238238
L3E -> S4 l1 L3E $ case l4 of
239239
L4 (LH2 l, r) rest ->
240-
L4 (LH0 (), r) (npushl (LN l) rest)
240+
L4 (LH0 (), r) (naiveInjectLeft (LN l) rest)
241241
L4E final -> L4E final
242242

243-
pushl :: a -> Queue a -> Queue a
244-
pushl a Q0 = QN (S4 L1E L3E (L4E (Final1 (L0 a))))
245-
pushl a (QN q) = QN (fix2l (npushl (L0 a) q))
243+
injectLeft :: a -> Queue a -> Queue a
244+
injectLeft a Q0 = QN (S4 L1E L3E (L4E (Final1 (L0 a))))
245+
injectLeft a (QN q) = QN (fix2ExposureLeft (naiveInjectLeft (L0 a) q))
246246

247-
npopl :: S4 a n L2Exposed rexposure ->
248-
(NLayered n Pair a, Maybe (S4 a n L0Exposed rexposure))
249-
npopl (S4 l1 l3 l4) = case l1 of
247+
naiveEjectLeft :: S4 a n L2Exposed rexposure ->
248+
(NLayered n Pair a, Maybe (S4 a n L0Exposed rexposure))
249+
naiveEjectLeft (S4 l1 l3 l4) = case l1 of
250250
L1L (LH1 a, RH1 r) m1 -> (a, Just rest) where
251251
rest = pushMU (LH0 (), RH1 r) (S4 m1 l3 l4)
252252
L1E -> case l3 of
@@ -264,43 +264,47 @@ npopl (S4 l1 l3 l4) = case l1 of
264264
L4E (Final2 a b) -> (a, Just (S4 L1E L3E (L4E (Final1 b))))
265265
L4E (Final1 a) -> (a, Nothing)
266266

267-
fix0l :: S4 a n L0Exposed rexposure ->
268-
S4 a n L2Exposed rexposure
269-
fix0l (S4 l1 l3 l4) = case l3 of
270-
L3L (LH0 (), RH1 r) m1 m2 m3 -> case npopl (push2l m1 m2 m3 l4) of
271-
(LN l, Just result) -> bestowL l1 (LH2 l, RH1 r) result
272-
(LN (Pair a b), Nothing) -> S4 l1 L3E (L4E (Final3 a b r))
267+
fix0ExposureLeft :: S4 a n L0Exposed rexposure ->
268+
S4 a n L2Exposed rexposure
269+
fix0ExposureLeft (S4 l1 l3 l4) = case l3 of
270+
L3L (LH0 (), RH1 r) m1 m2 m3 ->
271+
case naiveEjectLeft (push2l m1 m2 m3 l4) of
272+
(LN l, Just result) -> bestowL l1 (LH2 l, RH1 r) result
273+
(LN (Pair a b), Nothing) -> S4 l1 L3E (L4E (Final3 a b r))
273274
L3R level m1 m2 m3 -> bestowR l1 level $ case m3 of
274-
L3LL (LH0 (), RH1 r) n1 n2 n3 -> case npopl (push2l n1 n2 n3 l4) of
275-
(LN l, Just result) ->
276-
bestow2L m1 m2 (LH2 l, RH1 r) result
277-
(LN (Pair a b), Nothing) ->
278-
push2r m1 m2 L3LE (L4E (Final3 a b r))
275+
L3LL (LH0 (), RH1 r) n1 n2 n3 ->
276+
case naiveEjectLeft (push2l n1 n2 n3 l4) of
277+
(LN l, Just result) ->
278+
bestow2L m1 m2 (LH2 l, RH1 r) result
279+
(LN (Pair a b), Nothing) ->
280+
push2r m1 m2 L3LE (L4E (Final3 a b r))
279281
L3LE -> push2r m1 m2 L3LE $ case l4 of
280-
L4 (LH0 (), r) rest -> case npopl rest of
282+
L4 (LH0 (), r) rest ->
283+
case naiveEjectLeft rest of
284+
(LN l, Just new) -> L4 (LH2 l, r) new
285+
(LN (Pair a b), Nothing) -> case r of
286+
RH0 () -> L4E (Final2 a b)
287+
RH2 (Pair q r) -> L4E (Final4 a b q r)
288+
L4E final -> L4E final
289+
L3E -> S4 l1 L3E $ case l4 of
290+
L4 (LH0 (), r) rest ->
291+
case naiveEjectLeft rest of
281292
(LN l, Just new) -> L4 (LH2 l, r) new
282293
(LN (Pair a b), Nothing) -> case r of
283294
RH0 () -> L4E (Final2 a b)
284295
RH2 (Pair q r) -> L4E (Final4 a b q r)
285-
L4E final -> L4E final
286-
L3E -> S4 l1 L3E $ case l4 of
287-
L4 (LH0 (), r) rest -> case npopl rest of
288-
(LN l, Just new) -> L4 (LH2 l, r) new
289-
(LN (Pair a b), Nothing) -> case r of
290-
RH0 () -> L4E (Final2 a b)
291-
RH2 (Pair q r) -> L4E (Final4 a b q r)
292296
L4E final -> L4E final
293297

294-
popl :: Queue a -> Maybe (a, Queue a)
295-
popl Q0 = Nothing
296-
popl (QN q) = case npopl (fix0l q) of
298+
ejectLeft :: Queue a -> Maybe (a, Queue a)
299+
ejectLeft Q0 = Nothing
300+
ejectLeft (QN q) = case naiveEjectLeft (fix0ExposureLeft q) of
297301
(L0 a, Nothing) -> Just (a, Q0)
298302
(L0 a, Just q) -> Just (a, QN q)
299303

300-
npushr :: NLayered n Pair a ->
301-
S4 a n lexposure R0Exposed ->
302-
S4 a n lexposure R2Exposed
303-
npushr z (S4 l1 l3 l4) = case l1 of
304+
naiveInjectRight :: NLayered n Pair a ->
305+
S4 a n lexposure R0Exposed ->
306+
S4 a n lexposure R2Exposed
307+
naiveInjectRight z (S4 l1 l3 l4) = case l1 of
304308
L1L (LH1 l, RH1 r) m1 ->
305309
pushUM (LH1 l, RH2 (Pair r z)) (S4 m1 l3 l4)
306310
L1E -> case l3 of
@@ -319,34 +323,34 @@ npushr z (S4 l1 l3 l4) = case l1 of
319323
L4E (Final5 a p q r s) -> S4 (L1L (LH1 a, RH1 z) L1E)
320324
L3E (L4E (Final2 (LN (Pair p q)) (LN (Pair r s))))
321325

322-
fix2r :: S4 a n lexposure R2Exposed ->
323-
S4 a n lexposure R0Exposed
324-
fix2r (S4 l1 l3 l4) = case l3 of
326+
fix2ExposureRight :: S4 a n lexposure R2Exposed ->
327+
S4 a n lexposure R0Exposed
328+
fix2ExposureRight (S4 l1 l3 l4) = case l3 of
325329
L3R (LH1 l, RH2 r) m1 m2 m3 ->
326330
bestowR l1 (LH1 l, RH0 ()) $
327-
npushr (LN r) $
331+
naiveInjectRight (LN r) $
328332
push2r m1 m2 m3 l4
329333
L3L level m1 m2 m3 -> bestowL l1 level $ case m3 of
330334
L3RL (LH1 l, RH2 r) n1 n2 n3 ->
331335
bestow2R m1 m2 (LH1 l, RH0 ()) $
332-
npushr (LN r) $
336+
naiveInjectRight (LN r) $
333337
push2r n1 n2 n3 l4
334338
L3RE -> push2l m1 m2 L3RE $ case l4 of
335339
L4 (l, RH2 r) rest ->
336-
L4 (l, RH0 ()) (npushr (LN r) rest)
340+
L4 (l, RH0 ()) (naiveInjectRight (LN r) rest)
337341
L4E final -> L4E final
338342
L3E -> S4 l1 L3E $ case l4 of
339343
L4 (l, RH2 r) rest ->
340-
L4 (l, RH0 ()) (npushr (LN r) rest)
344+
L4 (l, RH0 ()) (naiveInjectRight (LN r) rest)
341345
L4E final -> L4E final
342346

343-
pushr :: a -> Queue a -> Queue a
344-
pushr z Q0 = QN (S4 L1E L3E (L4E (Final1 (L0 z))))
345-
pushr z (QN q) = QN (fix2r (npushr (L0 z) q))
347+
injectRight :: a -> Queue a -> Queue a
348+
injectRight z Q0 = QN (S4 L1E L3E (L4E (Final1 (L0 z))))
349+
injectRight z (QN q) = QN (fix2ExposureRight (naiveInjectRight (L0 z) q))
346350

347-
npopr :: S4 a n lexposure R2Exposed ->
348-
(NLayered n Pair a, Maybe (S4 a n lexposure R0Exposed))
349-
npopr (S4 l1 l3 l4) = case l1 of
351+
naiveEjectRight :: S4 a n lexposure R2Exposed ->
352+
(NLayered n Pair a, Maybe (S4 a n lexposure R0Exposed))
353+
naiveEjectRight (S4 l1 l3 l4) = case l1 of
350354
L1L (LH1 l, RH1 z) m1 -> (z, Just rest) where
351355
rest = pushUM (LH1 l, RH0 ()) (S4 m1 l3 l4)
352356
L1E -> case l3 of
@@ -364,35 +368,39 @@ npopr (S4 l1 l3 l4) = case l1 of
364368
L4E (Final2 y z) -> (z, Just (S4 L1E L3E (L4E (Final1 y))))
365369
L4E (Final1 z) -> (z, Nothing)
366370

367-
fix0r :: S4 a n lexposure R0Exposed ->
368-
S4 a n lexposure R2Exposed
369-
fix0r (S4 l1 l3 l4) = case l3 of
370-
L3R (LH1 l, RH0 ()) m1 m2 m3 -> case npopr (push2r m1 m2 m3 l4) of
371-
(LN r, Just result) -> bestowR l1 (LH1 l, RH2 r) result
372-
(LN (Pair a b), Nothing) -> S4 l1 L3E (L4E (Final3 l a b))
371+
fix0ExposureRight :: S4 a n lexposure R0Exposed ->
372+
S4 a n lexposure R2Exposed
373+
fix0ExposureRight (S4 l1 l3 l4) = case l3 of
374+
L3R (LH1 l, RH0 ()) m1 m2 m3 ->
375+
case naiveEjectRight (push2r m1 m2 m3 l4) of
376+
(LN r, Just result) -> bestowR l1 (LH1 l, RH2 r) result
377+
(LN (Pair a b), Nothing) -> S4 l1 L3E (L4E (Final3 l a b))
373378
L3L level m1 m2 m3 -> bestowL l1 level $ case m3 of
374-
L3RL (LH1 l, RH0 ()) n1 n2 n3 -> case npopr (push2r n1 n2 n3 l4) of
375-
(LN r, Just result) ->
376-
bestow2R m1 m2 (LH1 l, RH2 r) result
377-
(LN (Pair a b), Nothing) ->
378-
push2l m1 m2 L3RE (L4E (Final3 l a b))
379+
L3RL (LH1 l, RH0 ()) n1 n2 n3 ->
380+
case naiveEjectRight (push2r n1 n2 n3 l4) of
381+
(LN r, Just result) ->
382+
bestow2R m1 m2 (LH1 l, RH2 r) result
383+
(LN (Pair a b), Nothing) ->
384+
push2l m1 m2 L3RE (L4E (Final3 l a b))
379385
L3RE -> push2l m1 m2 L3RE $ case l4 of
380-
L4 (l, RH0 ()) rest -> case npopr rest of
386+
L4 (l, RH0 ()) rest ->
387+
case naiveEjectRight rest of
388+
(LN r, Just new) -> L4 (l, RH2 r) new
389+
(LN (Pair a b), Nothing) -> case l of
390+
LH0 () -> L4E (Final2 a b)
391+
LH2 (Pair q r) -> L4E (Final4 q r a b)
392+
L4E final -> L4E final
393+
L3E -> S4 l1 L3E $ case l4 of
394+
L4 (l, RH0 ()) rest ->
395+
case naiveEjectRight rest of
381396
(LN r, Just new) -> L4 (l, RH2 r) new
382397
(LN (Pair a b), Nothing) -> case l of
383398
LH0 () -> L4E (Final2 a b)
384399
LH2 (Pair q r) -> L4E (Final4 q r a b)
385-
L4E final -> L4E final
386-
L3E -> S4 l1 L3E $ case l4 of
387-
L4 (l, RH0 ()) rest -> case npopr rest of
388-
(LN r, Just new) -> L4 (l, RH2 r) new
389-
(LN (Pair a b), Nothing) -> case l of
390-
LH0 () -> L4E (Final2 a b)
391-
LH2 (Pair q r) -> L4E (Final4 q r a b)
392400
L4E final -> L4E final
393401

394-
popr :: Queue a -> Maybe (a, Queue a)
395-
popr Q0 = Nothing
396-
popr (QN q) = case npopr (fix0r q) of
402+
ejectRight :: Queue a -> Maybe (a, Queue a)
403+
ejectRight Q0 = Nothing
404+
ejectRight (QN q) = case naiveEjectRight (fix0ExposureRight q) of
397405
(L0 z, Nothing) -> Just (z, Q0)
398406
(L0 z, Just q) -> Just (z, QN q)

0 commit comments

Comments
 (0)