[Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell?

Nicholls, Mark Nicholls.Mark at mtvne.com
Thu Jan 3 07:48:17 EST 2008

Ahh ok I see what is meant by the parameter order....

-----Original Message-----
From: Peter Verswyvelen [mailto:peter.vers at telenet.be] On Behalf Of
Peter Verswyvelen
Sent: 03 January 2008 12:02
To: Nicholls, Mark
Cc: haskell-cafe at haskell.org
Subject: RE: [Haskell-cafe] Is there anyone out there who can translate
C# generics into Haskell?

Hi Mark,

>> "foo1 :: Int -> obj -> String"
> Yep...I think that's what I'd do....though I would have done...
> "foo1 :: obj -> Int -> String"
> Does that matter?

Well, it's a good habit in Haskell to move the "most important"
parameter to
the end of the argument list. See e.g.

> OK but I was going to go onto 
> Interface IX<A> where A : IX<A> {}
> and
> Interface IX<A,B> where A : B {}

No, I would not know how to that in Haskell using type classes. It seems
Haskell does not allow cycles in type class definitions. But as I'm new,
this does not mean it's not possible. It's more important to know *what*
are trying to do, than to give a solution in a different language, since
and FP are kind of orthogonal languages.

> Where I cannot see a way to do the above in Haskell at all....as
> interfaces effectively operator on type classes not types....which
> inherently more powerful

Yeah, kind of makes sense. I liked interfaces in C# a lot, but when I
started doing everything with interfaces, I found the lack of support
"mixins" or "default implementations" problematic. This ended up in a
lot of
copy/paste or encapsulating the implementations into a static class with
plain functions, a mess.

> But if these could be done in Haskell the see what could be made of
> stuff like....which is obviously problematic in C# it obviously
> work....but potentially does make 'sense'.
> Interface IX<A> : A {}

Ah! That's one of the bigger restrictions in C# yes! C++ can do that;
uses it a lot, and I also like that approach. You can emulate "mixins"
that, and still stay in the single inheritance paradigm. In Haskell you
don't do that at all of course, since you avoid thinking about "objects
inheritance" in the first place.

OO is strange. They offer you the nice concept of inheritance, and then
guidelines tell you: "don't use too many levels of inheritance"...
I've build huge projects using OO, it always felt a bit like unsafe
I don't really have that feeling with Haskell, but that could also be
because I'm too new to the language ;-)

> I'm looking at Haskell because of the formality of it's type
> system....but I'm actually not convinced it is as powerful as an OO
> one....i.e. OO ones operatate principally (in Haskell speak) on "type
> classes" not "types"

Maybe you are right, I don't know, my theoritical skills are not high
to answer that. Haskell just "feels" better to me, although the lack of
friendly productive IDE and large standard framework remains a bit of a

Good luck,

-----Original Message-----
From: haskell-cafe-bounces at haskell.org
[mailto:haskell-cafe-bounces at haskell.org] On Behalf Of Nicholls, Mark
Sent: Wednesday, January 02, 2008 5:41 PM
To: haskell-cafe at haskell.org
Subject: [Haskell-cafe] Is there anyone out there who can translate C#
generics into Haskell?

I'm trying to translate some standard C# constucts into Haskell... some
of this seems easy....



Interface IX


Interface IX<A>


Interface IX<A>
	Where A : IY


Interface IX<A> : IZ
	Where A : IY

I can take a punt at the first 2....but then it all falls apart
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org

More information about the Haskell-Cafe mailing list