From 797330650f71c62c4d93685b33a8af7cebc52d01 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 29 Nov 2017 13:07:15 -0500 Subject: [PATCH] Customize the default eval to show the constructor. --- src/Abstract/Eval.hs | 5 +++-- src/Data/Syntax.hs | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Abstract/Eval.hs b/src/Abstract/Eval.hs index 5f1afa1dd..acad379d1 100644 --- a/src/Abstract/Eval.hs +++ b/src/Abstract/Eval.hs @@ -12,6 +12,7 @@ import Abstract.Value import Control.Monad.Effect import Control.Monad.Effect.Reader import Control.Monad.Fail +import Data.Functor.Classes import Data.Proxy import Data.Semigroup import qualified Data.Set as Set @@ -23,8 +24,8 @@ import Prelude hiding (fail) -- Collecting evaluator class Monad m => Eval v m constr where eval :: FreeVariables term => ((v -> m v) -> term -> m v) -> (v -> m w) -> constr term -> m w - default eval :: (FreeVariables term, MonadFail m) => ((v -> m v) -> term -> m v) -> (v -> m w) -> constr term -> m w - eval _ _ _ = fail "default eval" + default eval :: (FreeVariables term, MonadFail m, Show1 constr) => ((v -> m v) -> term -> m v) -> (v -> m w) -> constr term -> m w + eval _ _ expr = fail $ "Eval unspecialized for " ++ liftShowsPrec (const (const id)) (const id) 0 expr "" instance (Monad m, Apply (Eval v m) fs) => Eval v m (Union fs) where eval ev yield = apply (Proxy :: Proxy (Eval v m)) (eval ev yield) diff --git a/src/Data/Syntax.hs b/src/Data/Syntax.hs index b476af5a6..c1bb1c0ec 100644 --- a/src/Data/Syntax.hs +++ b/src/Data/Syntax.hs @@ -183,7 +183,6 @@ instance Eq1 Error where liftEq = genericLiftEq instance Ord1 Error where liftCompare = genericLiftCompare instance Show1 Error where liftShowsPrec = genericLiftShowsPrec --- TODO: Define Value semantics for Error instance (MonadFail m) => Eval v m Error errorSyntax :: Error.Error String -> [a] -> Error a