Andrew Coppin | 13 Oct 20:48

Very silly

{-# 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?!?
Bulat Ziganshin | 13 Oct 20:57

Re: Very silly

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 <at> gmail.com
Andrew Coppin | 13 Oct 22:15

Re: Very silly

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...
Bulat Ziganshin | 13 Oct 22:31

Re[2]: Very silly

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 <at> gmail.com
Andrew Coppin | 13 Oct 22:40

Re: Very silly

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.]
David Leimbach | 14 Oct 00:30

Re: Re[2]: Very silly



On Mon, Oct 13, 2008 at 1:31 PM, Bulat Ziganshin <bulat.ziganshin <at> gmail.com> 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#

But they don't behave the same way.
 


--
Best regards,
 Bulat                            mailto:Bulat.Ziganshin <at> gmail.com

_______________________________________________

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Tony Morris | 14 Oct 00:33

Re: Very silly


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/

Tommy M. McGuire | 14 Oct 05:32

Re: Very silly

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 <at> crsr.net
Jason Dagit | 14 Oct 06:03

Re: Very silly



On Mon, Oct 13, 2008 at 8:32 PM, Tommy M. McGuire <mcguire <at> 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?

thanks,
Jason

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Tommy M. McGuire | 15 Oct 22:23

Re: Very silly

Jason Dagit wrote:
> On Mon, Oct 13, 2008 at 8:32 PM, Tommy M. McGuire <mcguire <at> crsr.net 
> <mailto:mcguire <at> 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 <at> crsr.net
Brad Larsen | 14 Oct 07:31

Re: Very silly

On Mon, 13 Oct 2008 23:32:30 -0400, Tommy M. McGuire <mcguire <at> crsr.net> wrote:

> 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
Luke Palmer | 14 Oct 17:10

Re: Very silly

On Mon, Oct 13, 2008 at 11:31 PM, Brad Larsen <brad.larsen <at> gmail.com> wrote:
> 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
Jonathan Cast | 13 Oct 22:05
Favicon

Re: Very silly

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
Andrew Coppin | 13 Oct 22:17

Re: Very silly

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...

Gmane