Is "Map" core or extension? What about Hashable & constraints? #221
Closed
acl-cqc
started this conversation in
Specification
Replies: 2 comments 4 replies
-
So what about:
|
Beta Was this translation helpful? Give feedback.
2 replies
-
This still isn't right. I think all the type arguments being hashable is a minimum for the constructed type being hashable. Maybe all we need is "hashable_if_args_are_hashable: bool" (being true/false) and similarly for classic_if.... |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In the current codebase,
Map(ClassicType,T)
is a T for both T=ClassicType and T=SimpleType. However, there are issues with this:insert<K,V>(map: Map<K,V>, key: K, value: V) -> Map<K,V>
. However, this can't parameterize over all key typesK
because types likeFloat
can't be hashed.We can solve the first by defining a subset of ClassicTypes that are Hashable, excluding Float. However, there is a further issue here - are Opaque types hashable? Trivially one can hash their serialized representation, but for a Map to work, this must be consistent with equality, which means opaque types must not have any notion of equality other than equality of serialized representations. Obviously all this is internal to the extension (operations), so the Hugr could gloss over it and declare all opaque types hashable. Or none. Or allow opaque types to declare whether they are hashable or not....
Moving the Map type out into an extension is possible but then either
If we want to allow CustomTypes to optionally implement Hashable, then there are two mechanisms which we could allow:
I note there is some commonality between Hashable and whether the type is a valid parameter to an OpDef or TypeDef, see #198. So, if we went with a Hashable constraint in core, and CustomTypes declaring whether they are hashable or not, then we could allow hashable CustomTypes to be used as parameters to OpDef/TypeDef, which is neat. This might then lead us to Resource YAML something like:
A final idea that I recall is that "the Map type doesn't care whether its elements are hashable - only the operations (get, put) do". There is some sense in this, but I'm not sure it solves (m)any of the problems...
Beta Was this translation helpful? Give feedback.
All reactions