Skip to content

Commit

Permalink
EncodedPath is now a newtype
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcadman committed Dec 19, 2023
1 parent e4a72e1 commit 092a2c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/Commands/Dev/Nockma/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions src/Juvix/Compiler/Nockma/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ data ParsedCell a
= ParsedOperatorCell (OperatorCell a)
| ParsedAutoConsCell (AutoConsCell a)

type EncodedPath = Natural
newtype EncodedPath = EncodedPath
{ _encodedPath :: Natural
}

data Direction
= L
Expand All @@ -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]
Expand All @@ -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 ()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 092a2c0

Please sign in to comment.