Copyright | Copyright (c) 2016 the Hakaru team |
---|---|
License | BSD3 |
Maintainer | wren@community.haskell.org |
Stability | experimental |
Portability | GHC-only |
Safe Haskell | None |
Language | Haskell2010 |
Bidirectional type checking for our AST.
Synopsis
- type TypeCheckError = Text
- data TypeCheckMonad a
- runTCM :: TypeCheckMonad a -> Input -> TypeCheckMode -> Either TypeCheckError a
- unTCM :: TypeCheckMonad a -> Ctx -> Input -> TypeCheckMode -> Either TypeCheckError a
- data TypeCheckMode
- inferable :: AST -> Bool
- mustCheck :: AST -> Bool
- data TypedAST (abt :: [Hakaru] -> Hakaru -> *) = TypedAST !(Sing b) !(abt '[] b)
- onTypedAST :: (forall b. abt '[] b -> abt '[] b) -> TypedAST abt -> TypedAST abt
- onTypedASTM :: Functor m => (forall b. abt '[] b -> m (abt '[] b)) -> TypedAST abt -> m (TypedAST abt)
- elimTypedAST :: (forall b. Sing b -> abt '[] b -> x) -> TypedAST abt -> x
- inferType :: forall abt. ABT Term abt => AST -> TypeCheckMonad (TypedAST abt)
- checkType :: forall abt a. ABT Term abt => Sing a -> AST -> TypeCheckMonad (abt '[] a)
The type checking monad
type TypeCheckError = Text Source #
data TypeCheckMonad a Source #
Instances
Monad TypeCheckMonad Source # | |
(>>=) :: TypeCheckMonad a -> (a -> TypeCheckMonad b) -> TypeCheckMonad b # (>>) :: TypeCheckMonad a -> TypeCheckMonad b -> TypeCheckMonad b # return :: a -> TypeCheckMonad a # fail :: String -> TypeCheckMonad a # | |
Functor TypeCheckMonad Source # | |
fmap :: (a -> b) -> TypeCheckMonad a -> TypeCheckMonad b # (<$) :: a -> TypeCheckMonad b -> TypeCheckMonad a # | |
Applicative TypeCheckMonad Source # | |
pure :: a -> TypeCheckMonad a # (<*>) :: TypeCheckMonad (a -> b) -> TypeCheckMonad a -> TypeCheckMonad b # liftA2 :: (a -> b -> c) -> TypeCheckMonad a -> TypeCheckMonad b -> TypeCheckMonad c # (*>) :: TypeCheckMonad a -> TypeCheckMonad b -> TypeCheckMonad b # (<*) :: TypeCheckMonad a -> TypeCheckMonad b -> TypeCheckMonad a # |
runTCM :: TypeCheckMonad a -> Input -> TypeCheckMode -> Either TypeCheckError a Source #
unTCM :: TypeCheckMonad a -> Ctx -> Input -> TypeCheckMode -> Either TypeCheckError a Source #
data TypeCheckMode Source #
Instances
Read TypeCheckMode Source # | |
readsPrec :: Int -> ReadS TypeCheckMode # readList :: ReadS [TypeCheckMode] # | |
Show TypeCheckMode Source # | |
showsPrec :: Int -> TypeCheckMode -> ShowS # show :: TypeCheckMode -> String # showList :: [TypeCheckMode] -> ShowS # |
Type checking itself
inferable :: AST -> Bool Source #
Those terms from which we can synthesize a unique type. We are also allowed to check them, via the change-of-direction rule.
mustCheck :: AST -> Bool Source #
Those terms whose types must be checked analytically. We cannot synthesize (unambiguous) types for these terms.
N.B., this function assumes we're in StrictMode
. If we're
actually in LaxMode
then a handful of AST nodes behave
differently: in particular, NaryOp_
, Superpose
, and
Case_
. In strict mode those cases can just infer one of their
arguments and then check the rest against the inferred type.
(For case-expressions, we must also check the scrutinee since
it's type cannot be unambiguously inferred from the patterns.)
Whereas in lax mode we must infer all arguments and then take
the lub of their types in order to know which coercions to
introduce.
data TypedAST (abt :: [Hakaru] -> Hakaru -> *) Source #
- Terms whose type is existentially quantified packed with a singleton for the type.
The e' ∈ τ
portion of the inference judgement.
onTypedAST :: (forall b. abt '[] b -> abt '[] b) -> TypedAST abt -> TypedAST abt Source #
onTypedASTM :: Functor m => (forall b. abt '[] b -> m (abt '[] b)) -> TypedAST abt -> m (TypedAST abt) Source #
elimTypedAST :: (forall b. Sing b -> abt '[] b -> x) -> TypedAST abt -> x Source #