From 092a2c0fccdbb7e427f6ae0434efac9af363d808 Mon Sep 17 00:00:00 2001 From: Paul Cadman Date: Tue, 19 Dec 2023 14:30:50 +0000 Subject: [PATCH] EncodedPath is now a newtype --- app/Commands/Dev/Nockma/Repl.hs | 2 +- src/Juvix/Compiler/Nockma/Language.hs | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Commands/Dev/Nockma/Repl.hs b/app/Commands/Dev/Nockma/Repl.hs index 6aaa3cc397..f4f2572b46 100644 --- a/app/Commands/Dev/Nockma/Repl.hs +++ b/app/Commands/Dev/Nockma/Repl.hs @@ -110,7 +110,7 @@ fromMegaParsecError = \case direction' :: String -> Repl () direction' s = Repline.dontCrash $ do let n = read s :: Natural - p = run (runFailDefault (error "invalid position") (decodePath n)) + p = run (runFailDefault (error "invalid position") (decodePath (EncodedPath n))) liftIO (putStrLn (ppPrint p)) readTerm :: String -> Repl (Term Natural) diff --git a/src/Juvix/Compiler/Nockma/Language.hs b/src/Juvix/Compiler/Nockma/Language.hs index 79c1a42f01..f38bbc3b8b 100644 --- a/src/Juvix/Compiler/Nockma/Language.hs +++ b/src/Juvix/Compiler/Nockma/Language.hs @@ -106,7 +106,9 @@ data ParsedCell a = ParsedOperatorCell (OperatorCell a) | ParsedAutoConsCell (AutoConsCell a) -type EncodedPath = Natural +newtype EncodedPath = EncodedPath + { _encodedPath :: Natural + } data Direction = L @@ -125,6 +127,7 @@ makeLenses ''AutoConsCell makeLenses ''Program makeLenses ''Assignment makeLenses ''WithStack +makeLenses ''EncodedPath naturalNockOps :: HashMap Natural NockOp naturalNockOps = HashMap.fromList [(serializeOp op, op) | op <- allElements] @@ -151,9 +154,9 @@ serializeOp = \case OpHint -> 11 decodePath :: forall r. (Member Fail r) => EncodedPath -> Sem r Path -decodePath ep = execOutputList (go ep) +decodePath ep = execOutputList (go (ep ^. encodedPath)) where - go :: EncodedPath -> Sem (Output Direction ': r) () + go :: Natural -> Sem (Output Direction ': r) () go = \case 0 -> fail 1 -> return () @@ -192,7 +195,7 @@ class (Eq a) => NockNatural a where nockPath :: (Member (Error (ErrNockNatural a)) r) => Atom a -> Sem r Path nockPath atm = do n <- nockNatural atm - failWithError (errInvalidPath atm) (decodePath n) + failWithError (errInvalidPath atm) (decodePath (EncodedPath n)) nockTrue :: Atom a nockFalse :: Atom a