4 ms·
> This does not seem to me to increase the expressivity of the language, whereas Haskell's type system does Some of us don't view that as a wanted feature. I
by brandonbloom 13y ago
> This does not seem to me to increase the expressivity of the language, whereas Haskell's type system does
Some of us don't view that as a wanted feature.
I wrote more optional/modular/pluggable type systems before. See: https://news.ycombinator.com/item?id=6196466 https://news.ycombinator.com/item?id=6196466
> polymorphic "return", or punts and doesn't do it
Haskell's type inferencer is doing a "search" for a type that fits and slotting that in there as an implicit argument. An error occurs if two match and you need to provide a type signature to differentiate. You could do precisely the same thing using first-class type objects, which Clojure has. Haskell has finally added them too, but required a compiler change. (See: Typeable).
That's how type classes work in general: A dictionary of methods has to be threaded through, unless the compiler can prove that the dictionary is a constant. Clojure does the same thing by embedding a pointer to that data in the first-class function object.
Let's assume I have a typed module. I could trivially query that module, since the type descriptions are data. That's what the Haskell compiler is doing, but with first-class types, I can do it myself. There is no reason that a user-level macro can't add enough inference to perform polymorphic returns.
But even if I could do this, I wouldn't want to. At most, I'd want an "infer-monad" form where I can explicitly say that I'm using my types to convey intent and am willing to pay the cost of coupling my program to a particular type system.
- kenko 13y ago> Some of us don't view that as a wanted feature. No doubt! But someone who was describing his or her fondness for Haskell's type system---the person I was initially responding to---probably does. I'm familiar (though not intimately familiar) with the idea of dictionary passing and with the fact that type classes are implemented that way. I'm not sure what the point of the remark in the present context is, though. I gather that you aren't a fan of the compiler doing this for you. (I'm not precisely sure what you mean by first-class type objects here, given the mention of Data.Typeable; concretely, I'm aware of three monad libraries that offer something like a polymorphic return and I know how two of them do it; one with symbol macros and regular old maps, and one that (in the presently released version) uses a run-monad function that threads through a regular old map. You presumably are thinking of something else; if so, I'd be glad to know what it is.) > There is no reason that a user-level macro can't add enough inference to perform polymorphic returns. Well, if you say so. I can't quite picture how this would work as a macro, but I'm not going to deny it can be done on that ground. FWIW, regarding your last sentence, I find the idea of a program separate from a particular type system kind of hard to grasp.