User loginNavigation |
Question concerning parameterization over literalsWe're currently looking at something in BitC, and I'm wondering if there may be a simpler way. I'm concerned that we may have gotten stuck in a "we know how to do types now, so everything is a typing problem" sort of rut. Background In BitC, we have both vectors and arrays. The size of an array is part of its type, but we presently have no way to abstract over that size. This means that we cannot currently build a type class for something like After some head scratching, we concluded that there is no fundamental problem with extending typeclass-style constraints and instantiation to incorporate instantiation over literals. The underlying observation is that every literal can be considered to be a member of some singleton type, and you can then abstract over that type in the usual way. So far so good. But as we dug into it a bit, we somehow moved from "abstraction over literals" to "abstraction over literal-associated singleton types". For example, our old specification of the array type constructor was:
where e must be a literal of type word. The new specification seems to have become:
where "T.len" is required to be a singleton literal type. In this case, that would be a constrained type of the form read: (forall ((Literal 'len Word)) (fn Stream (by-ref (mutable (array byte 'len))) 'len -> Word) meaning that read accepts a stream, an array by reference, and a length guaranteed to match the array length, and returns the number of characters read. All well and good, but from a usability perspective we still want to be able to write something simple like: (array char 2) For the moment, there are only a very few syntactic contexts where this would make sense, and Swaroop has proposed that we accept (interchangebly) either a singleton literal type or a value of singleton literal type and "lift" the value to its type in these syntactic contexts. And I think all of that will work. The Question While all of this ought to work, it feels like we are going around Robin Hood's barn here. Are there other languages that have dealt with this, and if so, what should we look at to understand better what has previously been done? By shap at 2008-11-06 15:20 | LtU Forum | previous forum topic | next forum topic | other blogs | 8092 reads
|
Browse archives
Active forum topics |
Recent comments
22 weeks 6 days ago
22 weeks 6 days ago
22 weeks 6 days ago
45 weeks 19 hours ago
49 weeks 2 days ago
50 weeks 6 days ago
50 weeks 6 days ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago