Skip to content

Commit

Permalink
fix type of inductive names
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Jul 21, 2022
1 parent 407082c commit be6e1e1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/Juvix/Syntax/MicroJuvix/InfoTable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ inductiveType v = do
let ps = info ^. inductiveInfoDef . inductiveParameters
return $
foldr
(\p k -> ExpressionFunction (typeAbs (p ^. inductiveParamName) k))
(ExpressionUniverse (SmallUniverse (getLoc v)))
(\_ k -> uni --> k)
(smallUniverse (getLoc v))
ps
where
typeAbs var = Function (typeAbstraction Explicit var)
uni = smallUniverse (getLoc v)

constructorArgTypes :: ConstructorInfo -> ([VarName], [Expression])
constructorArgTypes i =
Expand Down
14 changes: 14 additions & 0 deletions src/Juvix/Syntax/MicroJuvix/Language/Extra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,19 @@ reachableModules = fst . run . runOutputList . evalState (mempty :: HashSet Name
StatementInclude (Include inc) -> go inc
_ -> return ()

(-->) :: Expression -> Expression -> Expression
(-->) a b =
ExpressionFunction
( Function
( FunctionParameter
{ _paramName = Nothing,
_paramImplicit = Explicit,
_paramType = a
}
)
b
)

-- | Assumes the given function has been type checked
-- | NOTE: Registers the function *only* if the result is Type
functionDefEval :: FunctionDef -> Maybe Expression
Expand All @@ -448,6 +461,7 @@ functionDefEval f = case f ^. funDefClauses of
sparams <- mapM simpleExplicitParam nfirst
let r' = foldFunType rest r
return (sparams, r')
-- TODO normalize
isUniverse :: Expression -> Bool
isUniverse = \case
ExpressionUniverse {} -> True
Expand Down
2 changes: 1 addition & 1 deletion src/Juvix/Syntax/MicroJuvix/Pretty/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ instance PrettyCode FunctionParameter where
Just n -> do
paramName' <- ppCode n
paramType' <- ppCode _paramType
return $ implicitDelim _paramImplicit (paramName' <+> paramType')
return $ implicitDelim _paramImplicit (paramName' <+> kwColon <+> paramType')

instance PrettyCode Function where
ppCode (Function l r) = do
Expand Down
2 changes: 0 additions & 2 deletions src/Juvix/Syntax/MicroJuvix/TypeChecker/Inference.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ makeLenses ''MatchError
data Inference m a where
MatchTypes :: Expression -> Expression -> Inference m (Maybe MatchError)
QueryMetavar :: Hole -> Inference m (Maybe Expression)
WeakNormalize :: Expression -> Inference m Expression
RegisterIden :: Name -> Expression -> Inference m ()

makeSem ''Inference
Expand Down Expand Up @@ -141,7 +140,6 @@ re ::
re = reinterpret $ \case
MatchTypes a b -> matchTypes' a b
QueryMetavar h -> queryMetavar' h
WeakNormalize t -> weakNormalize' t
RegisterIden i ty -> registerIden' i ty
where
registerIden' :: Members '[State InferenceState] r => Name -> Expression -> Sem r ()
Expand Down
11 changes: 7 additions & 4 deletions tests/positive/TypeAlias.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ alias ≔ T;
x : alias;
x ≔ t;

id : Type -> Type;
id : Type Type;
id x ≔ x;

flip : (Type -> Type -> Type) -> Type -> Type -> Type;
flip : (Type Type Type) → id Type Type Type;
flip f a b ≔ f b a;

inductive Pair (A : Type) (B : Type) {
mkPair : id T -> id (id A) -> B -> Pair A B;
mkPair : id T id (id A) B Pair A B;
};

x' : flip Pair (id alias) T2;
p : {A : Type} → A → Pair A A;
p a ≔ mkPair t a a;

x' : flip Pair (id _) T2;
x' ≔ mkPair x t2 t;

end;

0 comments on commit be6e1e1

Please sign in to comment.