Bounded polymorphism
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1k
- Forks
- 212
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 65
Description
From microsoft/qsharp-language#149:
Is your feature request related to a problem? Please describe. When writing a polymorphic function in Q#, the type variables are fully general. They are opaque types with no properties that the function can rely on.
But there are many cases where a function needs a type to have certain properties. For example, a function may need its type variables to be equatable or comparable to store/retrieve them from a list or map. Arithmetic functions may also require that the types are numeric.
Describe the solution you'd like Q# needs some form of bounded polymorphism to be able to write functions that are valid for only certain types. I believe type classes are the best solution for this: they are very flexible and fit with Q#'s functional style.
Describe alternatives you've considered Overloading functions based on type (microsoft/qsharp-compiler#29) would solve the naming problem (e.g.
PlusI,PlusD,PlusLcould be overloaded toPlus), but this solution doesn't scale. Because the numeric types are not formally grouped, there is no way to write a single polymorphic function that calls the rightPlusautomatically - it similarly needs to be overloaded for each numeric type, creating unnecessary code duplication.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with microsoft/qsharp-language#149 and the bounded-polymorphism requirements in this issue; no implementation files or tests are identified. Clarify whether Q# should adopt type classes or another constraint mechanism, define the supported constraints and syntax, and agree on tests before implementation.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers, quantum-computing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100