Is it possible to create, in Scala, a type which is parametrized by a value? Instead of defining a partial type List[A] and parametrize it with List[Int], I'd like to define a partial type (in pseudo-code) Element[Symbol] and parametrize it with Element['td]. In this example, the type represent an XML element: Element['td] informs the Scala type checker that we have a <td> element, and you can imagine that one could have APIs that specifically expect or return <td> elements.
(Subclassing, as inclass Td extends Element, is not a very satisfactory solution, as it doesn't prevent two pieces of code, maybe written by independent developers, from declaring different subclasses for <td>, which will then be considered to be different types by the Scala type checker.)
If you really want to parameterize a type by a value, you need a dependently typed programming language such as Agda.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With