@@ -5,6 +5,7 @@ module Nock (tar, hax, fas, cell, atom, Annotation (..), Noun, RawNoun (..)) whe
55import Data.Hashable
66import Debug.Trace (trace, traceShowId)
77import GHC.Generics (Generic)
8+import GHC.Stack
89import Numeric.Natural
910import Test.QuickCheck.Arbitrary.Generic
1011
@@ -66,10 +67,11 @@ tis ~(Cell lhs rhs _) = if hashEq lhs rhs then sig else one
6667
6768fas :: Noun -> Noun
6869fas ~(Cell ~(Atom lhs _) rhs _) =
69− case traceShowId lhs of
70+ case lhs of
7071 1 -> rhs
7172 2 -> case rhs of
72− ~(Cell lhs' _ _) -> lhs'
73+ (Cell lhs' _ _) -> lhs'
74+ _ -> undefined
7375 3 -> case rhs of
7476 ~(Cell _ rhs' _) -> rhs'
7577 n
@@ -81,12 +83,12 @@ fas ~(Cell ~(Atom lhs _) rhs _) =
8183 _ -> undefined
8284
8385hax :: Noun -> Noun
84−hax ~(Cell ~(Atom n _) ~(Cell a b _) _) =
85− let (d, m) = divMod n 2
86+hax ~(Cell ~(Atom n _) ~(Cell b c _) _) =
87+ let (a, m) = divMod n 2
8688 in case n of
87− 1 -> a
88− _ | m == 0 -> hax (cell (atom d) (cell (cell a (fas (cell (atom $ n + 1) b))) b))
89− _ -> hax (cell (atom d) (cell (cell (fas (cell (atom $ n - 1) b)) a) b))
89+ 1 -> b
90+ _ | m == 0 -> hax (cell (atom a) (cell (cell b (fas (cell (atom $ a + a + 1) c))) c))
91+ _ -> hax (cell (atom a) (cell (cell (fas (cell (atom $ a + a) c)) b) c))
9092
9193tar :: Noun -> Noun
9294tar ~(Cell a ~(Cell b c _) _) = case b of
@@ -104,10 +106,10 @@ tar ~(Cell a ~(Cell b c _) _) = case b of
104106 8 -> tar $ cell (cell (tar $ cell a x) a) y
105107 9 -> tar $ cell (tar $ cell a y) $ cell (atom 2) (cell (cell sig one) (cell sig x))
106108 6 -> case y of
107− ~(Cell l k _) -> tar $ cell a $ tar $ cell (cell l k) $ cell sig $ tar $ cell (cell (atom 2) (atom 3)) $ cell sig $ tar $ cell a (cell (atom 4) (cell (atom 4) x))
109+ ~(Cell c' d' _) -> tar $ cell a $ tar $ cell (cell c' d') $ cell sig $ tar $ cell (cell (atom 2) (atom 3)) $ cell sig $ tar $ cell a (cell (atom 4) (cell (atom 4) x))
108110 10 -> case x of
109− ~(Cell l k _) -> hax $ cell l $ cell (tar (cell a k)) $ tar $ cell a y
111+ ~(Cell b' c' _) -> hax $ cell b' $ cell (tar (cell a c')) $ tar $ cell a y
110112 11 -> case x of
111− Cell _ k _ -> tar $ cell (cell (tar $ cell a k) (tar $ cell a y)) $ cell sig (atom 3)
113+ Cell _ c' _ -> tar $ cell (cell (tar $ cell a c') (tar $ cell a y)) $ cell sig (atom 3)
112114 Atom _ _ -> tar $ cell a y
113115 u -> error $ show u