Zulip Chat Archive
Stream: new members
Topic: Simplifying implicit arguments
lxsameer (Apr 02 2025 at 14:09):
Hy folks, is there any way to simplify the implicit arguments of the app
constructor? what's the best practice here?
inductive Expr : {n : Nat} -> (t : SType n) -> Type n where
| atom (s : String) : Expr SType.symbol
| fn { n m : Nat } {t : SType n } {t' : SType m} : (a : Expr t) -> (b : Expr t') -> Expr (SType.pie t t')
| app { n m : Nat } {t : SType n } {t'm : SType m} : (f : Expr (SType.pie t t')) -> Expr t -> Expr t'
deriving Repr
{ n m : Nat } {t : SType n } {t' : SType m}
is a pattern that I have to keep repeating.
Aaron Liu (Apr 02 2025 at 14:12):
You could try autoImplicit
Henrik Böving (Apr 02 2025 at 14:13):
Also note that the n
from your n : Nat
is not the same n
as in your Type n
. Universe variables and normal variables are distinct.
lxsameer (Apr 02 2025 at 14:14):
Thank you, yes I'm aware of that
Matt Diamond (Apr 02 2025 at 16:53):
what's the purpose of the Nat
s in your code, then?
lxsameer (Apr 02 2025 at 17:44):
What do you mean? I'm trying to model simple universes without using lean's universes. (the purpose, is me to learn more about lean and dependent type theory)
Matt Diamond (Apr 02 2025 at 17:45):
oh whoops, I saw SType
and thought it was Type
... I see what you're doing now
Matt Diamond (Apr 02 2025 at 17:45):
sorry!
Tomas Skrivan (Apr 02 2025 at 19:05):
Maybe I'm misunderstanding the question but are you also aware of the variable
command?
lxsameer (Apr 02 2025 at 19:27):
variable
like Agda's variable?
Matt Diamond (Apr 02 2025 at 21:25):
he means that you can write this:
variable { n m : Nat } {t : SType n } {t' : SType m}
and they will be automatically inserted as assumptions into all functions below
I'm not sure if that applies to constructor arguments, though...
Eric Wieser (Apr 02 2025 at 21:27):
Yeah, it will do the wrong thing for constructors
Eric Wieser (Apr 02 2025 at 21:28):
Could you make this a #mwe by including SType?
lxsameer (Apr 03 2025 at 11:41):
Here is the mwe:
import Std.Data.HashMap
inductive SType : (n : Nat) -> Type n
| universe : SType n
| symbol : SType 0
| pie {n m : Nat } (t : SType n) (t' : SType m) : SType (max n m)
| sigma {n m : Nat } (t : SType n) (t' : SType m) : SType (max n m)
deriving Repr
inductive Expr : {n : Nat} -> (t : SType n) -> Type n where
| atom : (s : String) -> Expr SType.symbol
| app : Expr (SType.pie t t') -> Expr t -> Expr t'
deriving Repr
inductive Value : {n : Nat} -> (t: SType n) -> Type n where
| fn : (arg : Expr t) -> (body : Expr t') -> Value (SType.pie t t')
| type : Value t
deriving Repr
inductive TypedValue : Type where
| mk : Value t → TypedValue
deriving Repr
structure Context where
env : Std.HashMap String TypedValue := Std.HashMap.empty
depth : Nat := 0
deriving Repr
def define (ctx : Context) (name : String) (value : Value t) : Context :=
{ ctx with
env := ctx.env.insert name (TypedValue.mk value)
}
def lookup (ctx : Context) (name : String) : Option TypedValue :=
ctx.env.get? name
Last updated: May 02 2025 at 03:31 UTC