perga/lib/Errors.hs

27 lines
1,012 B
Haskell
Raw Normal View History

2024-11-17 18:33:14 -08:00
module Errors where
import Data.Text (Text)
import qualified Data.Text as T
import Expr
data Error
= SquareUntyped
| UnboundVariable Text
| NotASort Expr Expr
| ExpectedPiType Expr Expr
| NotEquivalent Expr Expr Expr
2024-11-20 07:37:49 -08:00
| PNMissingType Text
| DuplicateDefinition Text
2024-11-17 18:33:14 -08:00
deriving (Eq, Ord)
instance Show Error where
show SquareUntyped = "□ does not have a type"
show (UnboundVariable x) = "Unbound variable: '" ++ T.unpack x ++ "'"
show (NotASort x t) = "Expected '" ++ prettyS x ++ "' to have type * or □, instead found '" ++ prettyS t ++ "'"
show (ExpectedPiType x t) = "'" ++ prettyS x ++ "' : '" ++ prettyS t ++ "' is not a function"
show (NotEquivalent a a' e) = "Cannot unify '" ++ prettyS a ++ "' with '" ++ prettyS a' ++ "' when evaluating '" ++ prettyS e ++ "'"
show (PNMissingType x) = "Axiom '" ++ T.unpack x ++ "' missing type ascription"
show (DuplicateDefinition n) = "'" ++ T.unpack n ++ "' already defined"
2024-11-17 18:33:14 -08:00
type Result = Either Error