Work on depdent tuped
Why no work
This commit is contained in:
parent
00a8b5b605
commit
bf6c9f7ae2
2 changed files with 108 additions and 0 deletions
32
dependent-types.lean
Normal file
32
dependent-types.lean
Normal file
|
@ -0,0 +1,32 @@
|
|||
|
||||
|
||||
-- Ok, from what I understnad dependent types are kind of the type
|
||||
-- equvileant to first-class functions. Types can be stored,
|
||||
-- returned, kinda like in zig.
|
||||
|
||||
-- Btw unicode is cool, reminds me of raku
|
||||
def α : Type := Nat
|
||||
-- α is a variable that stores the type
|
||||
#check α -- > α : Type
|
||||
|
||||
-- BTW #check is like eval but works for types
|
||||
|
||||
-- This is a function that takes a type and returns a type
|
||||
def F : Type → Type := List
|
||||
|
||||
#check F α
|
||||
|
||||
def IntOrString (isInt : Bool) : Type :=
|
||||
match isInt with
|
||||
| false => Int
|
||||
| true => String
|
||||
|
||||
#check IntOrString false
|
||||
|
||||
-- showOrReverse : (isInt : Bool) -> IntOrString isInt -> String
|
||||
def negateOrIdentity (isString : Bool) (val : IntOrString isString) : IntOrString isString :=
|
||||
match isString with
|
||||
| true => val
|
||||
| false => -val
|
||||
|
||||
#eval negateOrIdentity true "yo"
|
Loading…
Add table
Add a link
Reference in a new issue