mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
hopefully complete and correct typechecker in PGF
This commit is contained in:
@@ -14,7 +14,7 @@ def g0 = g2 ;
|
||||
fun g3 : Int -> (Int -> Int) ;
|
||||
def g3 3 = g ;
|
||||
|
||||
fun const : Int -> Int -> Int ;
|
||||
fun const : Float -> String -> Float ;
|
||||
def const x _ = x ;
|
||||
|
||||
cat Nat ;
|
||||
|
||||
@@ -1,34 +1,30 @@
|
||||
i testsuite/runtime/eval/Test.gf
|
||||
|
||||
pt -compute \x -> x 1
|
||||
pt -compute ? 1
|
||||
pt -compute (\x -> x 1) ?
|
||||
pt -compute unknown_var
|
||||
pt -compute unknown_var 1
|
||||
pt -compute 1 2
|
||||
pt -compute \x -> x 1 : (Int->Int)->Int
|
||||
pt -compute (? : Int -> Int) 1
|
||||
pt -compute (\x -> x 1 : (Int->Int)->Int) ?
|
||||
pt -compute f 1 2
|
||||
pt -compute \x -> x
|
||||
pt -compute ?666
|
||||
pt -compute \x -> x : Nat -> Nat
|
||||
pt -compute ? : String
|
||||
pt -compute f
|
||||
pt -compute (\x -> x 2) (f 1)
|
||||
pt -compute (\x -> x 2) 1
|
||||
pt -compute (\x -> x 2 : (Int->Int)->Int) (f 1)
|
||||
pt -compute g 1
|
||||
pt -compute g 0
|
||||
pt -compute \x -> g x
|
||||
pt -compute \x -> g x : Int -> Int
|
||||
pt -compute g ?
|
||||
pt -compute (\x -> x 5) (g2 1)
|
||||
pt -compute (\x -> x 3) (\x -> x)
|
||||
pt -compute (\x -> x 5 : (Int->Int)->Int) (g2 1)
|
||||
pt -compute (\x -> x 3 : (Int->Int)->Int) (\x -> x)
|
||||
pt -compute g0
|
||||
pt -compute (\x -> x 3.2) (\x -> f x)
|
||||
pt -compute g0 2.3
|
||||
pt -compute g0 ((\x -> f x) 0) 1
|
||||
pt -compute (\x -> x 32 : (Int -> Int -> Int) -> Int -> Int) (\x -> f x : Int -> Int -> Int)
|
||||
pt -compute g0 23
|
||||
pt -compute const 3.14 "pi"
|
||||
pt -compute dec (succ (succ zero))
|
||||
pt -compute dec (succ ?)
|
||||
pt -compute \x -> dec x
|
||||
pt -compute \x -> dec x : Nat -> Nat
|
||||
pt -compute dec ?
|
||||
pt -compute (\f -> f 0) (g3 ?)
|
||||
pt -compute (\f -> f 0 : (Int -> Int) -> Int) (g3 ?)
|
||||
pt -compute g (g2 ? 0)
|
||||
pt -compute plus (succ zero) (succ zero)
|
||||
pt -compute dec2 0 (succ zero)
|
||||
pt -compute dec2 0 err
|
||||
pt -compute plus err (succ zero)
|
||||
@@ -1,30 +1,26 @@
|
||||
\v0 -> v0 1
|
||||
\x -> x 1
|
||||
|
||||
|
||||
|
||||
|
||||
? 1
|
||||
?1 1
|
||||
|
||||
|
||||
|
||||
? 1
|
||||
|
||||
|
||||
|
||||
?3 1
|
||||
|
||||
|
||||
|
||||
|
||||
f 1 2
|
||||
|
||||
|
||||
|
||||
|
||||
\x -> x
|
||||
|
||||
|
||||
|
||||
|
||||
?1
|
||||
|
||||
?666
|
||||
|
||||
|
||||
f
|
||||
|
||||
@@ -32,29 +28,29 @@ g ?
|
||||
|
||||
f 1 2
|
||||
|
||||
f 1 2
|
||||
|
||||
|
||||
|
||||
|
||||
literal of function type
|
||||
2
|
||||
|
||||
|
||||
|
||||
g 0
|
||||
|
||||
g 0
|
||||
|
||||
|
||||
|
||||
\x -> g x
|
||||
|
||||
\v0 -> g v0
|
||||
|
||||
|
||||
|
||||
g ?1
|
||||
|
||||
g ?
|
||||
|
||||
|
||||
5
|
||||
|
||||
|
||||
|
||||
3
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
\v0 -> v0
|
||||
\x -> x
|
||||
|
||||
|
||||
|
||||
1
|
||||
1
|
||||
|
||||
|
||||
|
||||
|
||||
\x -> x
|
||||
|
||||
|
||||
37
testsuite/runtime/typecheck/Test.gf
Normal file
37
testsuite/runtime/typecheck/Test.gf
Normal file
@@ -0,0 +1,37 @@
|
||||
abstract Test = {
|
||||
|
||||
cat Nat ;
|
||||
data zero : Nat ;
|
||||
succ : Nat -> Nat ;
|
||||
|
||||
fun plus : Nat -> Nat -> Nat ;
|
||||
def plus zero n = n ;
|
||||
plus (succ m) n = plus m (succ n) ;
|
||||
|
||||
cat Vector Nat ;
|
||||
fun vector : (n : Nat) -> Vector n ;
|
||||
|
||||
fun append : (m,n : Nat) -> Vector m -> Vector n -> Vector (plus m n) ;
|
||||
fun diff : (m,n : Nat) -> Vector (plus m n) -> Vector m -> Vector n ;
|
||||
|
||||
cat Morph (Nat -> Nat) ;
|
||||
fun mkMorph : (f : Nat -> Nat) -> Morph f ;
|
||||
fun mkMorph2 : (f : Nat -> Nat) -> Vector (f zero) -> Morph f ;
|
||||
fun idMorph : Morph (\x -> x) -> Nat ;
|
||||
|
||||
fun f0 : (n : Nat) -> ((m : Nat) -> Vector n) -> Int ;
|
||||
fun f1 : (n : Nat -> Nat) -> ((m : Nat) -> Vector (n m)) -> Int ;
|
||||
|
||||
fun cmpVector : (n : Nat) -> Vector n -> Vector n -> Int ;
|
||||
|
||||
fun g : ((n : Nat) -> Vector n) -> Int ;
|
||||
|
||||
cat U (n,m : Nat) ;
|
||||
fun u0 : (n : Nat) -> U n n ;
|
||||
fun u1 : (n : Nat) -> U n (succ n) ;
|
||||
fun h : (n : Nat) -> U n n -> Int ;
|
||||
|
||||
-- fun u2 : (n : Nat) -> U (plus n zero) zero ;
|
||||
-- fun h2 : (f : Nat -> Nat) -> ((n : Nat) -> U (f n) (f zero)) -> Int ;
|
||||
|
||||
}
|
||||
30
testsuite/runtime/typecheck/typecheck.gfs
Normal file
30
testsuite/runtime/typecheck/typecheck.gfs
Normal file
@@ -0,0 +1,30 @@
|
||||
i testsuite/runtime/typecheck/Test.gf
|
||||
|
||||
ai succ "0"
|
||||
ai succ : Int 0
|
||||
ai 1 2
|
||||
ai (\x -> x 2 : (Int->Int)->Int) 1
|
||||
ai unknown_fun
|
||||
ai 0 : unknown_cat
|
||||
ai \x -> x
|
||||
ai \x -> x : Int
|
||||
ai append (succ (succ zero)) (succ zero) (vector (succ (succ zero))) (vector (succ zero))
|
||||
ai \m,n -> vector (plus m n) : (m,n : Nat) -> Vector (plus m n)
|
||||
ai mkMorph (\x -> succ zero)
|
||||
ai idMorph (mkMorph (\x -> x))
|
||||
ai idMorph (mkMorph (\x -> succ zero))
|
||||
ai append zero (succ zero) : Vector zero -> Vector (succ zero) -> Vector (succ zero)
|
||||
ai \n,v1,n,v2 -> append ? ? v1 v2 : (n : Nat) -> Vector n -> (m : Nat) -> Vector m -> Vector (plus n m)
|
||||
ai \n -> (\v1,v2 -> eqVector n v1 v2 : Vector ? -> Vector ? -> EQ) (vector ?) : (n : Nat) -> Vector n -> EQ
|
||||
ai (\v1,v2 -> cmpVector ? v1 v2 : Vector ? -> Vector ? -> Int) (vector ?)
|
||||
ai f0 ? vector
|
||||
ai f1 ? vector
|
||||
ai f1 ? (\x -> vector (succ x))
|
||||
ai mkMorph (\x -> cmpVector ? (vector x) (vector (succ x)))
|
||||
ai g (\n -> vector (succ n))
|
||||
ai h ? (u0 ?)
|
||||
ai h ? (u1 ?)
|
||||
ai cmpVector (succ (succ zero)) (vector (succ (succ zero))) (append ? (succ zero) (vector ?) (vector (succ zero)))
|
||||
ai diff ? (succ (succ zero)) (vector (succ (succ (succ (succ (succ zero)))))) (vector (succ (succ (succ zero))))
|
||||
ai diff ? (succ (succ zero)) (vector (succ (succ (succ (succ zero))))) (vector (succ (succ (succ zero))))
|
||||
ai idMorph (mkMorph2 (\x -> ?) (vector zero))
|
||||
102
testsuite/runtime/typecheck/typecheck.gfs.gold
Normal file
102
testsuite/runtime/typecheck/typecheck.gfs.gold
Normal file
@@ -0,0 +1,102 @@
|
||||
|
||||
|
||||
Couldn't match expected type Nat
|
||||
|
||||
against inferred type String
|
||||
|
||||
In the expression: "0"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Category Int should have 0 argument(s), but has been given 1
|
||||
|
||||
In the type: Int 0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
A function type is expected for the expression 1 instead of type Int
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Couldn't match expected type Int -> Int
|
||||
|
||||
against inferred type Int
|
||||
|
||||
In the expression: 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Function unknown_fun is not in scope
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Category unknown_cat is not in scope
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Cannot infer the type of expression \x -> x
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
A function type is expected for the expression \x -> x instead of type Int
|
||||
|
||||
|
||||
|
||||
Expression: append (succ (succ zero)) (succ zero) (vector (succ (succ zero))) (vector (succ zero))
|
||||
|
||||
Type: Vector (plus (succ (succ zero)) (succ zero))
|
||||
|
||||
|
||||
|
||||
Expression: \m, n -> vector (plus m n) : (m : Nat) -> (n : Nat) -> Vector (plus m n)
|
||||
|
||||
Type: (m : Nat) -> (n : Nat) -> Vector (plus m n)
|
||||
|
||||
|
||||
|
||||
Expression: mkMorph (\x -> succ zero)
|
||||
|
||||
Type: Morph (\x -> succ zero)
|
||||
|
||||
|
||||
|
||||
Expression: idMorph (mkMorph (\x -> x))
|
||||
|
||||
Type: Nat
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Couldn't match expected type Morph (\x -> x)
|
||||
|
||||
against inferred type Morph (\x -> succ zero)
|
||||
|
||||
In the expression: mkMorph (\x -> succ zero)
|
||||
|
||||
|
||||
|
||||
Expression: append zero (succ zero) : Vector zero -> Vector (succ zero) -> Vector (succ zero)
|
||||
|
||||
Type: Vector zero -> Vector (succ zero) -> Vector (succ zero)
|
||||
|
||||
|
||||
|
||||
Expression: \n, v1, n'1, v2 -> append n n'1 v1 v2 : (n : Nat) -> Vector n -> (m : Nat) -> Vector m -> Vector (plus n m)
|
||||
|
||||
Type: (n : Nat) -> Vector n -> (m : Nat) -> Vector m -> Vector (plus n m)
|
||||
|
||||
Reference in New Issue
Block a user