Zulip Chat Archive
Stream: general
Topic: product / tuple / pair type?
JJ (Jun 20 2024 at 04:12):
Hello! I would like to write something like | tuple (fields : List (Product (Option Key) Value))
, but have been unable to find what the equivalent of a Tuple
is in Lean...
JJ (Jun 20 2024 at 04:14):
I know I could do this by defining a structure Field where (key: Option Key) (value: Value)
and pointing the List
to that, but it feels unnecessary - I think I'm definitely missing some sort of inline product type. But, I've been searching through documentation and code and have been unable to find one. Any pointers would be appreciated!
JJ (Jun 20 2024 at 04:15):
(also - would this be the correct topic for questions & discussion of lean as a general purpose programming language?)
Kim Morrison (Jun 20 2024 at 04:15):
Prod
Kim Morrison (Jun 20 2024 at 04:15):
We just use iterated pairs for tuples (with a bit of syntax help).
JJ (Jun 20 2024 at 04:16):
Syntax help? :eyes:
Kim Morrison (Jun 20 2024 at 04:16):
i.e. you can just write (a, b, c)
and Lean understands it as (a, (b, c))
JJ (Jun 20 2024 at 04:17):
Ah nice! is there any sugar for type declarations or would that just be (Prod A (Prod B C))
?
Kim Morrison (Jun 20 2024 at 04:18):
A × B × C
Kim Morrison (Jun 20 2024 at 04:19):
I suggest reading #FPIL
Kim Morrison (Jun 20 2024 at 04:19):
Kim Morrison (Jun 20 2024 at 04:19):
JJ (Jun 20 2024 at 04:25):
Oh, I don't know how I missed that... looks like I missed everything after Options, whoops
JJ (Jun 20 2024 at 04:25):
Ty :sweat_smile:
JJ (Jun 20 2024 at 04:39):
Follow-up question: is it possible to define names ((a : A) × (b : B) × (c : C))
in product types or does that require a named structure
?
Kim Morrison (Jun 20 2024 at 04:44):
No
Last updated: May 02 2025 at 03:31 UTC