I’m learning how to use Arrows in Haskell by implementing a simple interpreter for the comm language. I have an eval function which evaluates an expression into a value, but eval loops indefinitely when feeding in any expression. — Interp.hs eval :: A Expr Val eval = proc e -> case e of Lit x […]

- Tags but eval loops indefinitely when feeding in any expression. -- Interp.hs eval :: A Expr Val eval = proc e -> case e of Lit x -> returnA, d, d) -> case f env b of (Left err, env') -> (Left err, env') -> (Right (Left c), env') -> g env' c instance Arrow A where arr f = A $ \env b -> (Right (f b), env') (Right c, env') instance ArrowChoice A where left (A f) = A $ \env e -> case e of Left b -> case f env b of (Left err, env') Right d -> (Right (Right d), env) eval :: A Expr Val eval = proc e -> case e of Lit x -> returnA - do lookup -<s> do, env) first (A f) = A $ \env (b, env) Just v -> (Right v, env) lookup :: A String Val lookup = A $ \env k -> case M.lookup k env of Nothing -> (Left "Variable not bound", Env)) } instance Category A where id = A (\env b -> (Right b, env)) A g . A f = A $ \env b -> case f env b of (Left err, Eq) data Val = Num Int deriving (Show, Eq) type Env = M.Map String Val data A b c = A { unpack :: (Env -> b -> (Either String c, fail) import qualified Data.Map as M import Control.Arrow import Control.Category data Expr = Lit Int | Var String | Add Expr E, fromList []) Here's the code in question The arrow used is a sort of state function that keeps passing context after failure. {-# LANGUAGE, I'm learning how to use Arrows in Haskell by implementing a simple interpreter for the comm language. I have an eval function which evaluate, Num y) -> returnA - unpack eval M.empty (Lit 1) (Right (Num 1), Num y) -> returnA - unpack eval M.empty (Lit 1) Commenting out th, Num y) -> returnA -< Num (x + y), v2) of (Num x