
On Tue, 2007-09-04 at 16:06 +0200, Peter Verswyvelen wrote:
Henning Thielemann wrote:
If you are happy with writing "do {1;2;3;4}" you are certainly also happy with "cv [1,2,3,4]", where cv means 'convert' and is a method of a class for converting between lists and another sequence type.
class ListCompatible lc where cv :: [a] -> lc a rt :: lc a -> [a] {- restore :-) -}
Better don't adapt the names, but the idea would work, wouldn't it?
Oh but I will not write "do {1;2;3;4}", this was just an idea :-) Yep, your approach certainly works, but I just found it was a bit of a discrepancy in Haskell (numbers getting better lifting support than lists).
I don't think this has been mentioned explicitly yet, but the discrepancy is purely for pedagogical purposes. In Gofer, list comprehensions (and list syntax, IIRC) /was/ generalized (to an arbitrary instance of MonadPlus). But that means that any mistake in your syntax likely brings up a type error mentioning MonadPlus. This confuses CS freshmen (who are easily confused anyway); thus, Haskell restricts list syntax to lists so the type errors are simpler. By contrast, most CS freshman have already used languages with multiple number types, so all you have to do is explain that type errors involving Num are Haskell's way of dealing with them. So the syntax can be generalized to the type class in that case without confusing freshmen as much. jcc