Fix RHole, add test files, papers, piforall examples

This commit is contained in:
2024-08-22 22:07:45 -07:00
parent 9db5649446
commit 2c20cadd09
9 changed files with 238 additions and 3 deletions

50
newt/Fix.newt Normal file
View File

@@ -0,0 +1,50 @@
module Fix
-- from piforall Fix.pi
Type: U
Type = U
-- TODO piforall makes the A in scope for the constructors
-- and has it on the let of the :
-- I think we want that for parameters?
data D : (A : Type) -> Type where
F : {A : Type} -> (D A -> D A) -> D A
V : {A : Type} -> A -> D A
-- Here we have two A in play, so y is type of the
-- A in V and the expected return value is the other.
-- We do need to sort this out
unV : { A : U} -> D A -> A
unV = \ v => case v of
V y => ? -- y
-- F f => TRUSTME
-- And here we have D A:4 and D A:1
unF : {A : Type} -> D A -> D A -> D A
unF = \ {A} v x =>
case v of
F {A} f => ? -- f x
-- V y => TRUSTME
-- fix : {A : U} -> (A -> A) -> A
-- fix = \ {A} g =>
-- -- RLet is not yet implemented...
-- let omega = -- : D A -> D A =
-- (\ x => V (g (unv {A} (unF {A} x x))))
-- in unV {A} (omega (F omega))
-- data Nat : Type where
-- Zero : Nat
-- Succ : Nat -> Nat
-- fix_add : Nat -> Nat -> Nat
-- fix_add = fix [Nat -> Nat -> Nat]
-- \radd. \x. \y.
-- case x of
-- Zero -> y
-- Succ n -> Succ (radd n y)
-- test : fix_add 5 2 = 7
-- test = Refl

View File

@@ -1,5 +1,10 @@
module Scratch
-- I'm testing cases here, but using examples carefully design to be
-- simple case trees. Patterns are a var or a constructor applied to vars.
-- There are indexes below, but we're got pulling constraints out of them yet.
data Nat : U where
Z : Nat
S : Nat -> Nat

43
newt/testprim.newt Normal file
View File

@@ -0,0 +1,43 @@
module TestPrim
-- we need to be able to declare a primitive type
-- distinct from inductive type. there are no constructors per-se but it is inhabited
ptype String
ptype Int
pfunc strlen : String -> Int := "(x) => x.length()"
-- why is there an eta in here?
foo : String -> Int
foo = \ x => strlen x
bar : String -> String -> Int
bar = \ x y => strlen x
pfunc append : String -> String -> String := "(a,b) => a + b"
blah : String
blah = append "hello" "world"
pfunc plus : Int -> Int -> Int := "(a,b) => a + b"
answer : Int
answer = plus 40 2
-- I'd like to define prim operators too
-- codegen test cases
-- works, but two looks like () => (eta1) => (eta0) => one(eta1, eta0)
pfunc one : Int -> Int -> Int := "(x,y) => x + y"
two : Int -> Int -> Int
two = one
three : Int -> Int -> Int
three = \ x => two x
four : Int -> Int -> Int
four = \x y => three x y