-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unification to interpreter + tui
- Loading branch information
1 parent
1466f76
commit 1a4acd7
Showing
12 changed files
with
167 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module Sigil.Analysis.FormulaCheck | ||
( check_formula ) where | ||
|
||
import Control.Monad.Except (MonadError, throwError) | ||
|
||
import Prettyprinter | ||
|
||
import Sigil.Abstract.Names | ||
import Sigil.Abstract.Unify | ||
import Sigil.Abstract.Environment | ||
import Sigil.Analysis.Typecheck | ||
import Sigil.Concrete.Resolved | ||
import Sigil.Concrete.Decorations.Range | ||
import Sigil.Concrete.Internal | ||
|
||
|
||
check_formula :: (MonadGen m, MonadError err m, Environment Name e) | ||
=> CheckInterp m err e InternalCore -> e (Maybe InternalCore,InternalCore) | ||
-> Formula Name ResolvedCore -> m (Formula Name InternalCore) | ||
check_formula interp@(CheckInterp {..}) env formula = case formula of | ||
Conj scons -> Conj <$> mapM (check_scons interp env) scons | ||
And l r -> And <$> check_formula interp env l <*> check_formula interp env r | ||
Bind q n ty f -> do | ||
(ty', kind) <- infer interp env ty | ||
ty_norm <- normalize (lift_err . flip NormErr mempty) env kind ty' | ||
let env' = insert n (Nothing, ty_norm) env | ||
Bind q n ty_norm <$> check_formula interp env' f | ||
|
||
|
||
check_scons :: (MonadGen m, MonadError err m, Environment Name e) | ||
=> CheckInterp m err e InternalCore -> e (Maybe InternalCore,InternalCore) | ||
-> SingleConstraint ResolvedCore -> m (SingleConstraint InternalCore) | ||
check_scons interp@(CheckInterp {..}) env cons = case cons of | ||
(l :≗: r) -> do | ||
(l', lty) <- infer interp env l | ||
(r', rty) <- infer interp env r | ||
(_, kind) <- infer interp env lty | ||
check_eq mempty interp env kind lty rty | ||
l_norm <- normalize (lift_err . flip NormErr mempty) env lty l' | ||
r_norm <- normalize (lift_err . flip NormErr mempty) env rty r' | ||
pure $ (l_norm :≗: r_norm) | ||
(val :∈: ty) -> do | ||
(ty', kind) <- infer interp env ty | ||
ty_norm <- normalize (lift_err . flip NormErr mempty) env kind ty' | ||
val' <- check interp env val ty_norm | ||
val_norm <- normalize (lift_err . flip NormErr mempty) env ty_norm val' | ||
pure $ (val_norm :≗: ty_norm) | ||
|
||
|
||
check_eq :: (MonadError err m, Pretty a) => Range -> (CheckInterp m err e a) -> e (Maybe a, a) -> a -> a -> a -> m () | ||
check_eq range (CheckInterp {..}) env ty l r | ||
= | ||
αβη_eq (lift_err . flip NormErr range) env ty l r >>= \case | ||
True -> pure () | ||
False -> throwError $ lift_err $ PrettyErr ("not-equal:" <+> pretty l <+> "and" <+> pretty r) range |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.