Preliminary work on data and holes
This commit is contained in:
14
newt/data.newt
Normal file
14
newt/data.newt
Normal file
@@ -0,0 +1,14 @@
|
||||
module Data
|
||||
|
||||
-- The code to handle this is full of TODO
|
||||
-- stuff is not checked and it's not read as data, just
|
||||
-- type signatures.
|
||||
|
||||
data Nat : U where
|
||||
Z : Nat
|
||||
S : Nat -> Nat
|
||||
|
||||
-- My initial version of this needed unbound implicits
|
||||
data Maybe : U -> U where
|
||||
Nothing : {a : U} -> Maybe a
|
||||
Just : {a : U} -> a -> Maybe a
|
||||
15
newt/eq.newt
Normal file
15
newt/eq.newt
Normal file
@@ -0,0 +1,15 @@
|
||||
module Equality
|
||||
|
||||
-- we don't have implicits yet, so this won't typecheck
|
||||
|
||||
Eq : {A : U} -> A -> A -> U
|
||||
Eq = \ {A} => \ x => \ y => (P : A -> U) -> P x -> P y
|
||||
|
||||
refl : {A : U} {x : A} -> Eq x x
|
||||
refl = \ {A} => \ {x} => x
|
||||
|
||||
-- can I write J without pattern matching?
|
||||
J : {A : U} {x y : A} (eq : Eq x y) ->
|
||||
(mot : (x : A) (P : Eq x y) -> U)
|
||||
(b : mot y refl) ->
|
||||
mot x eq
|
||||
18
newt/ex.newt
Normal file
18
newt/ex.newt
Normal file
@@ -0,0 +1,18 @@
|
||||
-- foo
|
||||
module Foo
|
||||
|
||||
id : (a : U) -> a -> a
|
||||
id = \ a => \ x => x
|
||||
|
||||
-- if I put foo here, it fails with 'extra toks' at "module"
|
||||
-- errors aren't cutting to the top
|
||||
-- I think we need the errors to be fatal if anything is consumed (since the nearest alt)
|
||||
|
||||
List : U -> U
|
||||
List = \ A => (L : U) -> L -> (A -> L -> L) -> L
|
||||
|
||||
nil : (A : U) -> List A
|
||||
nil = \ A L n f => n
|
||||
|
||||
Bool : U
|
||||
|
||||
32
newt/zoo2.newt
Normal file
32
newt/zoo2.newt
Normal file
@@ -0,0 +1,32 @@
|
||||
module Zoo2
|
||||
|
||||
id : (A : U) -> A -> A
|
||||
id = \ A x => x
|
||||
|
||||
const : (A B : U) -> A -> B -> A
|
||||
const = \A B x y => x
|
||||
|
||||
Nat : U
|
||||
Nat = (N : U) -> (N -> N) -> N -> N
|
||||
|
||||
-- need Nat to reduce (and syntax highlighting)
|
||||
five : Nat
|
||||
five = \ N s z => s (s (s (s (s z))))
|
||||
|
||||
add : Nat -> Nat -> Nat
|
||||
add = \a b N s z => a N s (b N s z)
|
||||
|
||||
mul : Nat -> Nat -> Nat
|
||||
mul = \a b N s z => a N (b N s) z
|
||||
|
||||
ten : Nat
|
||||
ten = add five five
|
||||
|
||||
hundred : Nat
|
||||
hundred = mul ten ten
|
||||
|
||||
thousand : Nat
|
||||
thousand = mul ten hundred
|
||||
|
||||
-- and then nf / eval of hundred
|
||||
-- #nf hundred
|
||||
7
newt/zoo3.newt
Normal file
7
newt/zoo3.newt
Normal file
@@ -0,0 +1,7 @@
|
||||
module Zoo3
|
||||
|
||||
id : (A : _) -> A -> A
|
||||
id = \ A x => x
|
||||
|
||||
List : U -> U
|
||||
List = \ A => (L : _) -> (A -> L -> L) -> L -> L
|
||||
Reference in New Issue
Block a user