Opaque type subtyping with generics does not maintain exactness
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Hello beloved type people,
I believe I'm experiencing an issue having to do with opaque types, generics and exactness. I'm afraid it's not demonstrable directly in flow.org/try/ as it requires operating outside the module where the opaque type is defined.
My use case is that I want to be able to flag values with types, so what I need is some kind of container type. I want to be able to create functions which expect values having been explicitly flagged by the developer, so the type needs to be opaque. I also want to be able to pass the flagged values to functions expecting the unflagged value. These taken together mean I need something of the form `opaque type F: A = A`.
This mostly works great. There's a problem if you assign an exact type to the type argument `A`, though: you can't assign a value of `F` to a variable of `A`, because `A` will be exact but `F` will not.
Here's a gist with code to replicate and an error: https://gist.github.com/Ezku/3db645a8b9f9f9835a2b102577f0da5b
Am I doing something wrong? Can I fix this in the code or is it an issue with flow? (I've never done OCaml yet, but is there somewhere you could point me to in case I could contribute a fix?) 🤔
Thanks,
Eevert
PS. Please do let me know if I can improve on this issue somehow, it's my first one here! 🙏
Contributor guide
Assessment
This issue has not been assessed yet.