Zulip Chat Archive

Stream: new members

Topic: inductive map


Huỳnh Trần Khanh (Jun 09 2021 at 06:00):

why is the "inductive map" construction the most common way to define a map? inductive map is like... the map is represented by a function from KeyType to ValueType, and the set key operation is implemented by function composition

Huỳnh Trần Khanh (Jun 09 2021 at 06:00):

why is it implemented by a function and not a list for example

Huỳnh Trần Khanh (Jun 09 2021 at 06:01):

of course a tree wouldn't be practical since that would require the key to support total ordering

Mario Carneiro (Jun 09 2021 at 06:01):

I'm not sure why you call that inductive, or most common

Mario Carneiro (Jun 09 2021 at 06:01):

it's certainly most general

Huỳnh Trần Khanh (Jun 09 2021 at 06:02):

https://github.com/blanchette/logical_verification_2020/blob/master/lean/lovelib.lean#L193

Huỳnh Trần Khanh (Jun 09 2021 at 06:02):

this is what I'm referring to

Huỳnh Trần Khanh (Jun 09 2021 at 06:02):

I have seen it several times in functional programming books

Mario Carneiro (Jun 09 2021 at 06:02):

it's convenient because it is easy to reason about

Mario Carneiro (Jun 09 2021 at 06:02):

it's not efficient at all

Mario Carneiro (Jun 09 2021 at 06:02):

it is basically a linear search built with thunks

Mario Carneiro (Jun 09 2021 at 06:03):

The important property you usually need about the lookup function is that it is equivalent to state.update

Mario Carneiro (Jun 09 2021 at 06:03):

so making it true by definition makes things easier

Mario Carneiro (Jun 09 2021 at 06:05):

it is possible to prove such a property for lookup functions implemented in a more efficient way, for example src#hash_map.mem_insert, but it is complicated and also comes with restrictions on the key type


Last updated: Dec 20 2023 at 11:08 UTC