Zulip Chat Archive
Stream: new members
Topic: Subtype polymorphism
Martin Dvořák (Feb 02 2022 at 18:39):
Is there a way how to use a term of a subtype in place of an argument expecting a term of its parent type without having to write subtype.val
in front of the term? I hope Lean has this automatic conversion (or rather, subtype polymorphism).
Junyan Xu (Feb 02 2022 at 18:43):
x.val or x.1 ?
Eric Wieser (Feb 02 2022 at 18:51):
You can write (x : the_parent_type)
Martin Dvořák (Feb 02 2022 at 18:51):
Junyan Xu said:
x.val or x.1 ?
OK, that is better than subtype.val x
but still not what I wanted.
Martin Dvořák (Feb 02 2022 at 18:52):
Eric Wieser said:
You can write
(x : the_parent_type)
And can it be inferred automatically? When I write the term in a position of argument of type the_parent_type
please?
Alex J. Best (Feb 02 2022 at 18:58):
Did you try it? Works fine for me in this example
def foo : ℕ → ℕ := id
def t : { x // x * x = 4 } := ⟨2, by refl⟩
#check foo t
Martin Dvořák (Feb 02 2022 at 19:08):
Alex J. Best said:
Did you try it? Works fine for me in this example
def foo : ℕ → ℕ := id def t : { x // x * x = 4 } := ⟨2, by refl⟩ #check foo t
Your code works on my computer. However, when I do an analogous thing with my types, it doesn't work. Let me play with it for a while; if I don't manage to make it work in the same way, I will create a MWE from my code.
Last updated: Dec 20 2023 at 11:08 UTC