Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow named arguments in type synonyms #2343

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ data InferenceState = InferenceState
makeLenses ''InferenceState

iniState :: InferenceState
iniState = InferenceState mempty mempty
iniState =
InferenceState
{ _inferenceMap = mempty,
_inferenceIdens = mempty
}

closeState ::
(Member (Error TypeCheckerError) r) =>
Expand Down Expand Up @@ -429,25 +433,27 @@ addIdens idens = do
-- some condition.
functionDefEval :: forall r'. (Members '[State FunctionsTable, Termination, Error TypeCheckerError] r') => FunctionDef -> Sem r' (Maybe Expression)
functionDefEval f = do
r <- runFail goTop
retTy <- returnsType
(params :: [FunctionParameter], ret :: Expression) <- unfoldFunType <$> strongNorm (f ^. funDefType)
let retTy = isUniverse ret
r <- runFail (goTop params retTy)
when (isNothing r && retTy) (throw (ErrUnsupportedTypeFunction (UnsupportedTypeFunction f)))
return r
where
isUniverse :: (Members '[State FunctionsTable] r) => Expression -> Sem r Bool
isUniverse e = do
e' <- evalState iniState (weakNormalize' e)
case e' of
ExpressionUniverse {} -> return True
_ -> return False

(params, ret) = unfoldFunType (f ^. funDefType)

returnsType :: (Members '[State FunctionsTable] r) => Sem r Bool
returnsType = isUniverse ret

goTop :: forall r. (Members '[Fail, State FunctionsTable, Error TypeCheckerError, Termination] r) => Sem r Expression
goTop = do
strongNorm :: (Members '[State FunctionsTable] r) => Expression -> Sem r Expression
strongNorm = evalState iniState . strongNormalize'

isUniverse :: Expression -> Bool
isUniverse = \case
ExpressionUniverse {} -> True
_ -> False

goTop ::
forall r.
(Members '[Fail, State FunctionsTable, Error TypeCheckerError, Termination] r) =>
[FunctionParameter] ->
Bool ->
Sem r Expression
goTop params returnsType = do
checkTerminating
case f ^. funDefClauses of
c :| [] -> goClause c
Expand All @@ -465,12 +471,12 @@ functionDefEval f = do
splitExplicitParams :: Sem r [Expression]
splitExplicitParams = do
let n = length (c ^. clausePatterns)
unlessM returnsType fail
unless returnsType fail
nfirst <- failMaybe (takeExactMay n params)
mapM simpleExplicitParam nfirst
simpleExplicitParam :: FunctionParameter -> Sem r Expression
simpleExplicitParam = \case
FunctionParameter Nothing Explicit ty -> return ty
FunctionParameter _ Explicit ty -> return ty
_ -> fail
goPattern :: (Pattern, Expression) -> Expression -> Sem r Expression
goPattern (p, ty) = case p of
Expand Down
11 changes: 9 additions & 2 deletions tests/positive/Internal/Synonyms.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import Stdlib.Prelude open;

Ty1 : Type := Bool → Bool;

Ty2 : Type := Ty1;
idTy (A : Type) : Type := A;

idTy2 : typeToType
| A := A;

typeToType : Type := Type -> Type;

Ty2 : idTy Type := Ty1;

k : Ty2
| x := x;
Expand All @@ -15,5 +22,5 @@ Num : Type := {A : Type} → (A → A) → A → A;
czero : Num
| {_} f x := x;

csuc : Num → Num
csuc : idTy2 Num → idTy Num
| n {_} f := f ∘ n {_} f;
Loading