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

Nicholls, Mark Nicholls.Mark at mtvne.com
Thu Jan 3 05:06:25 EST 2008


>-- C#: interface IX1 { String foo1(int); }
>class IX1 obj where 
>  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?

>-- C#: interface IX2<A> { String foo2(A); }
>class IX2 obj a where 
>  foo2 :: a -> obj -> String

Ok same here

>--C#: interface IX3<A> where A : IY { String foo3(A); }
>class IY a where {- ... -}
>class IY a => IX3 obj a where 
>  foo3 :: a -> obj -> String

Yep I think again I would have guessed at that

>--C#: interface IX4<A> : IZ where A : IY
>class IZ a where {- ... -}
>class (IY a, IZ obj) => IX4 obj a where
>  foo4 :: a -> obj -> String

Hmmmm...this would have been one of my guesses....but let me have a

>This assumes your "objects" are immutable, otherwise you would have to
>return (obj,String) instead of just String and then you most likely
want to
>use the state monad and "do notation" to make functional programming
>more like imperative programming.

This is fine....my oop is largely immutable.

>You really have to drop the OO way of thinking, 
>which I find the hardest :)
>Haskell's type classes are more powerful in some sense than C#
>for example, in C# you can't attach an interface to any class (take for
>example the Point struct), it has to be your own class, while in
>you can implement an instance of a type class for any datatype!

OK but I was going to go onto 

Interface IX<A> 
	where A : IX<A>


Interface IX<A,B> 
	where A : B

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

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

>Hope this helps a bit. As I'm new myself to Haskell, so take this with
>"grain of salt".

It does...I will have a go with your sample answers.

>Once you bite the bullet, I found Haskell a lot more fun than C#,
>C# of course comes with a gigantic .NET framework and tools...

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"


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