module DDC.Core.Tetra.Convert.Base
( ConvertM
, Error (..))
where
import DDC.Core.Exp
import DDC.Base.Pretty
import DDC.Core.Check (AnTEC(..))
import DDC.Core.Tetra.Prim as E
import qualified DDC.Control.Monad.Check as G
type ConvertM a x = G.CheckM () (Error a) x
data Error a
= ErrorMainHasNoMain
| ErrorMalformed String
| ErrorMistyped (Exp (AnTEC a E.Name) E.Name)
| ErrorUnsupported (Exp (AnTEC a E.Name) E.Name) Doc
| ErrorBotAnnot
| ErrorUnexpectedSum
| ErrorInvalidBinder E.Name
| ErrorInvalidBound (Bound E.Name)
| ErrorInvalidDaCon (DaCon E.Name)
| ErrorInvalidAlt
instance Show a => Pretty (Error a) where
ppr err
= case err of
ErrorMalformed str
-> vcat [ text "Module is malformed."
, text str ]
ErrorMistyped xx
-> vcat [ text "Module is mistyped." <> (text $ show xx) ]
ErrorUnsupported xx doc
-> vcat [ text "Cannot convert expression."
, indent 2 $ doc
, empty
, indent 2 $ text "with:" <+> ppr xx ]
ErrorBotAnnot
-> vcat [ text "Found bottom type annotation."
, text "Program should be type-checked before conversion." ]
ErrorUnexpectedSum
-> vcat [ text "Unexpected type sum."]
ErrorInvalidBinder n
-> vcat [ text "Invalid name used in binder '" <> ppr n <> text "'."]
ErrorInvalidBound n
-> vcat [ text "Invalid name used in bound occurrence " <> ppr n <> text "."]
ErrorInvalidDaCon n
-> vcat [ text "Invalid data constructor name " <> ppr n <> text "." ]
ErrorInvalidAlt
-> vcat [ text "Invalid alternative." ]
ErrorMainHasNoMain
-> vcat [ text "Main module has no 'main' function." ]