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

Peter Verswyvelen bf3 at telenet.be
Thu Jan 3 07:02:07 EST 2008


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.
http://www.haskell.org/haskellwiki/Parameter_order. 

> 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* you
are trying to do, than to give a solution in a different language, since OO
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 seems
> 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 for
"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 doesn't
> 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; ATL
uses it a lot, and I also like that approach. You can emulate "mixins" with
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 and
inheritance" in the first place.

OO is strange. They offer you the nice concept of inheritance, and then the
guidelines tell you: "don't use too many levels of inheritance"... Although
I've build huge projects using OO, it always felt a bit like unsafe hacking.
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 enough
to answer that. Haskell just "feels" better to me, although the lack of a
friendly productive IDE and large standard framework remains a bit of a
burden.

Good luck,
Peter

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

Specifically

1) 

Interface IX
{
}

2)

Interface IX<A>
{
}

3)

Interface IX<A>
	Where A : IY
{
}

4)

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
http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list