learning-lean-prover/dependent-types.lean
2025-05-22 23:19:29 +10:00

32 lines
832 B
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 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"