modify Eq function

This commit is contained in:
Rowan Torbitzky-Lane 2025-02-05 01:05:51 -06:00
parent e40ef0ce62
commit add949ed05

View File

@ -8,6 +8,7 @@ import State
deleteAt :: Int -> [a] -> [a] deleteAt :: Int -> [a] -> [a]
deleteAt idx xs = take idx xs <> drop 1 (drop idx xs) deleteAt idx xs = take idx xs <> drop 1 (drop idx xs)
-- I could probably just combine these functions
combineTuple :: a -> ([a], [a]) -> [a] combineTuple :: a -> ([a], [a]) -> [a]
combineTuple val tup = fst tup <> [val] <> snd tup combineTuple val tup = fst tup <> [val] <> snd tup
@ -140,13 +141,13 @@ instructionFlush state accessor = state & accessor .~ []
instructionEq :: forall a. Eq a => State -> Lens' State [a] -> State instructionEq :: forall a. Eq a => State -> Lens' State [a] -> State
instructionEq state accessor = instructionEq state accessor =
case uncons stackTop of case uncons $ view accessor state of
Nothing -> state Nothing -> state
Just (x1, x2 : _) -> state & bool .~ (x1 == x2) : view bool state & accessor .~ drop 2 (view accessor state) Just (x1, x2 : _) -> droppedState & bool .~ (x1 == x2) : view bool droppedState
Just _ -> state Just _ -> state
where where
stackTop :: [a] droppedState :: State
stackTop = take 2 $ view accessor state droppedState = state & accessor .~ drop 2 (view accessor state)
instructionStackDepth :: State -> Lens' State [a] -> State instructionStackDepth :: State -> Lens' State [a] -> State
instructionStackDepth state@(State {_int = is}) accessor = state{_int = length (view accessor state) : is} instructionStackDepth state@(State {_int = is}) accessor = state{_int = length (view accessor state) : is}