
{-# LANGUAGE FlexibleInstances #-} module Overload where class Silly s where go :: s instance Silly ([x] -> [x]) where go = reverse instance Silly (Int -> Int) where go = (+1) Don't even ask. Suffice it to say, you *can* make Haskell support arbitrary overloading of function names like C++ has, _if_ you abuse the type system violently enough. Please, won't somebody think of the children?!?

Hello Andrew, Monday, October 13, 2008, 10:51:43 PM, you wrote:
Suffice it to say, you *can* make Haskell support arbitrary overloading of function names like C++ has, _if_ you abuse the type system violently enough. Please, won't somebody think of the children?!?
people that make critique on haskell type classes, don't take into account that it's unlike C++ templates, implemented via run-time dictionaries and other modules may define new instances just imagine other module defining instance for (a->a) or (String->String) - how your module should compile calls to `go` that take into account these possible definitions -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

Bulat Ziganshin wrote:
people that make critique on haskell type classes, don't take into account that it's unlike C++ templates, implemented via run-time dictionaries and other modules may define new instances
Personally, I have no clue how C++ templates work [yet]. (As in, I'm learning C++, but I haven't got to that chapter yet.) Some guy told me that templates are "the best feature in the language", and proceeded to show me a huge chunk of highly complex-looking code which is approximately equivilent to join :: Array x -> Array x -> Array x I was unimpressed. Actually, that's a lie. I was impressed that such a low-level language could manage even that much abstraction. But I still prefer the Haskell way...

Hello Andrew, Tuesday, October 14, 2008, 12:15:04 AM, you wrote:
people that make critique on haskell type classes, don't take into account that it's unlike C++ templates, implemented via run-time dictionaries and other modules may define new instances
Personally, I have no clue how C++ templates work [yet]. (As in, I'm
they are known as generics in java/c# -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

Bulat Ziganshin wrote:
Hello Andrew,
Tuesday, October 14, 2008, 12:15:04 AM, you wrote:
people that make critique on haskell type classes, don't take into account that it's unlike C++ templates, implemented via run-time dictionaries and other modules may define new instances
Personally, I have no clue how C++ templates work [yet]. (As in, I'm
they are known as generics in java/c#
I don't know C#, and when I did Java, generics didn't exist yet. [Eiffel has a feature of the same name, but I don't think it's related - certainly not in implementation anyway.]

On Mon, Oct 13, 2008 at 1:31 PM, Bulat Ziganshin
Hello Andrew,
Tuesday, October 14, 2008, 12:15:04 AM, you wrote:
people that make critique on haskell type classes, don't take into account that it's unlike C++ templates, implemented via run-time dictionaries and other modules may define new instances
Personally, I have no clue how C++ templates work [yet]. (As in, I'm
they are known as generics in java/c#
But they don't behave the same way.
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Bulat Ziganshin wrote:
Hello Andrew,
Tuesday, October 14, 2008, 12:15:04 AM, you wrote:
people that make critique on haskell type classes, don't take into account that it's unlike C++ templates, implemented via run-time dictionaries and other modules may define new instances
Personally, I have no clue how C++ templates work [yet]. (As in, I'm
they are known as generics in java/c#
Except they're not. Java Generics are something else altogether. - -- Tony Morris http://tmorris.net/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFI88ydmnpgrYe6r60RAinKAKCeuK7gQovCyNsdDg9E0j0uBxQymACgrZIW oVuW1DBpepVxF9sXlKoRIbU= =jv6U -----END PGP SIGNATURE-----

Andrew Coppin wrote:
Bulat Ziganshin wrote:
people that make critique on haskell type classes, don't take into account that it's unlike C++ templates, implemented via run-time dictionaries and other modules may define new instances
Personally, I have no clue how C++ templates work [yet]. (As in, I'm learning C++, but I haven't got to that chapter yet.)
Some guy told me that templates are "the best feature in the language", and proceeded to show me a huge chunk of highly complex-looking code which is approximately equivilent to
join :: Array x -> Array x -> Array x
I was unimpressed.
Actually, that's a lie. I was impressed that such a low-level language could manage even that much abstraction. But I still prefer the Haskell way...
C++ values have sizes: class foo { int x; }; is half (ahem; make that "different from") the size of class bar { int x; int y; }; As a result, doing parametric polymorphism requires duct taping something suspiciously similar to cpp macros to the type system. Hence, how C++ templates work: weirdly. Java (and presumably C#) "generics" are very much like a weakened version of normal parametric polymorphism. C++ templates are an attempt at the same thing in a completely different landscape. I'd be willing to bet that Some Guy's code was very close to exactly equivalent to your join. Now, as to what C++ templates have to do with Haskell type classes, I dunno... -- Tommy M. McGuire mcguire@crsr.net

Jason Dagit wrote:
On Mon, Oct 13, 2008 at 8:32 PM, Tommy M. McGuire
mailto:mcguire@crsr.net> wrote: Java (and presumably C#) "generics" are very much like a weakened version of normal parametric polymorphism. I'm curious, in what way are they weakened?
That's a good question. :-) I picked up the idea while reading Java Generics and Collections, but I can no longer find the part that *gave* me the impression. I suspect that it is due to the type erasure vs. array runtime typing issues. It may be the case that basic generics are identical to plain parametric polymorphism, and that the wildcard expressions attempt to serve the same purpose (with considerable divergence) as type classes and existential types. But I don't know since my brains have apparently turned to oatmeal. -- Tommy M. McGuire mcguire@crsr.net

On Mon, 13 Oct 2008 23:32:30 -0400, Tommy M. McGuire
Andrew Coppin wrote:
Bulat Ziganshin wrote:
people that make critique on haskell type classes, don't take into account that it's unlike C++ templates, implemented via run-time dictionaries and other modules may define new instances
Personally, I have no clue how C++ templates work [yet]. (As in, I'm learning C++, but I haven't got to that chapter yet.)
Some guy told me that templates are "the best feature in the language", and proceeded to show me a huge chunk of highly complex-looking code which is approximately equivilent to
join :: Array x -> Array x -> Array x
I was unimpressed.
Actually, that's a lie. I was impressed that such a low-level language could manage even that much abstraction. But I still prefer the Haskell way...
C++ values have sizes:
class foo { int x; };
is half (ahem; make that "different from") the size of
class bar { int x; int y; };
As a result, doing parametric polymorphism requires duct taping something suspiciously similar to cpp macros to the type system. Hence, how C++ templates work: weirdly.
Java (and presumably C#) "generics" are very much like a weakened version of normal parametric polymorphism. C++ templates are an attempt at the same thing in a completely different landscape. I'd be willing to bet that Some Guy's code was very close to exactly equivalent to your join.
Now, as to what C++ templates have to do with Haskell type classes, I dunno...
In the next C++ standard, type checking capabilities are being added to templates---"concepts" specify a set of operations a templated type must support. See http://en.wikipedia.org/wiki/C%2B%2B0x#Concepts. Seems somewhat similar to Haskell typeclasses to me, but perhaps the similarity is merely superficial. :-) Regards, Brad Larsen

On Mon, Oct 13, 2008 at 11:31 PM, Brad Larsen
In the next C++ standard, type checking capabilities are being added to templates---"concepts" specify a set of operations a templated type must support. See http://en.wikipedia.org/wiki/C%2B%2B0x#Concepts. Seems somewhat similar to Haskell typeclasses to me, but perhaps the similarity is merely superficial. :-)
A professor of mine, Jeremy Siek, was a major proponent of concepts on the design committee. If I recall correctly, he mentioned Haskell typeclasses as a direct inspiration. Incidentally, Concepts will flaunt more features than typeclasses to CEOs everywhere because C++ does not have inference to worry about (and already has an undecidable compile time, so what would it have to lose?). Luke

On Mon, 2008-10-13 at 19:51 +0100, Andrew Coppin wrote:
{-# LANGUAGE FlexibleInstances #-}
module Overload where
class Silly s where go :: s
instance Silly ([x] -> [x]) where go = reverse
instance Silly (Int -> Int) where go = (+1)
Don't even ask.
Suffice it to say, you *can* make Haskell support arbitrary overloading of function names like C++ has, _if_ you abuse the type system violently enough. Please, won't somebody think of the children?!?
Flexible instances are extroardinarily useful: instance Monad m => MonadState s (StateT s m) instance MonadState t m => MonadState (s, t) (StateT s m) is a useful and not entirely insane instance scheme. But yeah, anyone who uses class Silly in real life should be banned from coming within a 100 feet of any place where math, science, engineering, or software development is carried out or taught. I don't know if it's necessary for the good of the Children, but we need to start thinking of the poor, defenseless computers as well... jcc

Jonathan Cast wrote:
Flexible instances are extroardinarily useful:
I'm sure the GHC team wouldn't have bothered otherwise. ;-) AFAIK, "flexible instances" just means that absolutely anything can be a class instance, right?
instance Monad m => MonadState s (StateT s m) instance MonadState t m => MonadState (s, t) (StateT s m)
is a useful and not entirely insane instance scheme.
I hadn't realised this required FIs. (Although clearly it demands MPTCs.) Man, so many TLAs...
But yeah, anyone who uses class Silly in real life should be banned from coming within a 100 feet of any place where math, science, engineering, or software development is carried out or taught.
I don't know if it's necessary for the good of the Children, but we need to start thinking of the poor, defenseless computers as well...
Heh. And I thought *I* was crewl for making my poor PC use Peano integers rather than the [vastly more efficient] binary numbers...
participants (9)
-
Andrew Coppin
-
Brad Larsen
-
Bulat Ziganshin
-
David Leimbach
-
Jason Dagit
-
Jonathan Cast
-
Luke Palmer
-
Tommy M. McGuire
-
Tony Morris