1
1
mirror of https://github.com/anoma/juvix.git synced 2024-11-28 09:45:58 +03:00

Support positive arity typealias in arity checker (#2021)

Currently the arity checker assumes that applications within a type
signature have arity unit. This is not the case where a type alias
function is used within a type signature that returns a positive arity
function type.

For example:

```
type T :=
  | t : T;

funAlias : Type -> Type;
funAlias a := a -> a;

f : funAlias T;
f t := t;
```

* Closes https://github.com/anoma/juvix/issues/2020

Co-authored-by: Co-authored-by: janmasrovira <janmasrovira@gmail.com>
This commit is contained in:
Paul Cadman 2023-04-20 11:07:37 +01:00 committed by GitHub
parent 3d012cc8fb
commit c4d519ae09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -435,7 +435,7 @@ typeArity = go
go :: Expression -> Arity go :: Expression -> Arity
go = \case go = \case
ExpressionIden i -> goIden i ExpressionIden i -> goIden i
ExpressionApplication {} -> ArityUnit ExpressionApplication a -> goApplication a
ExpressionLiteral {} -> ArityUnknown ExpressionLiteral {} -> ArityUnknown
ExpressionFunction f -> ArityFunction (goFun f) ExpressionFunction f -> ArityFunction (goFun f)
ExpressionHole {} -> ArityUnknown ExpressionHole {} -> ArityUnknown
@ -445,6 +445,14 @@ typeArity = go
ExpressionSimpleLambda {} -> simplelambda ExpressionSimpleLambda {} -> simplelambda
ExpressionLet l -> goLet l ExpressionLet l -> goLet l
goApplication :: Application -> Arity
goApplication a = case lhs of
ExpressionIden IdenInductive {} -> ArityUnit
_ -> ArityUnknown
where
lhs :: Expression
lhs = fst (unfoldApplication a)
goLet :: Let -> Arity goLet :: Let -> Arity
goLet l = typeArity (l ^. letExpression) goLet l = typeArity (l ^. letExpression)

View File

@ -34,3 +34,15 @@ p a := mkPair t a a;
x' : flip Pair (id _) T2; x' : flip Pair (id _) T2;
x' := mkPair x t2 t; x' := mkPair x t2 t;
funAlias : Type -> Type;
funAlias a := a -> a;
f : funAlias T;
f :=
\ {
| t := t
};
f' : funAlias T;
f' t := t;