3 ms·
(define (compress l) (fold combine identity l)) The inferred type will be ((Transformation :t) => (List :t) -> :t)
by reikonomusha 5y ago
(define (compress l)
(fold combine identity l))
The inferred type will be
((Transformation :t) => (List :t) -> :t)
- jakear 5y agoHow does it pick which identity to use? If I compress the empty list is that a translation by 0,0 a dilation by 1, or a rotation by 0? I don't love the ambiguity here.
- reikonomusha 5y agoYou can't pass that list. That would be a type error. The list must be (List :t), and :t can't change from element to element. In other words, it's not valid if you can't fill in :t. A rotation has type :t = Rotation; a dilation has type :t = Dilation. It can't be both at the same time. If you wanted to be able to do this, you'd either (1) need a more powerful type system, or (2) express all kinds of transformations into a single sum type.
- jakear 5y agoWell thats... limiting. But reasonable I suppose. If you go the sum type route would you then need to implement identify specifically for the sum type?