Re: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell?
"Peter Verswyvelen" <[EMAIL PROTECTED]> writes: > 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. I must say I like these recommendations. As for the Data.Map examples, the parameter order was changed compared to the old FiniteMap, and I was sure there was some rationale given? -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell?
Ahh ok I see what is meant by the parameter order -Original Message- From: Peter Verswyvelen [mailto:[EMAIL PROTECTED] On Behalf Of Peter Verswyvelen Sent: 03 January 2008 12:02 To: Nicholls, Mark Cc: haskell-cafe@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 dothough 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 where A : IX {} > and > Interface IX 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 allas > interfaces effectively operator on type classes not typeswhich 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 likewhich is obviously problematic in C# it obviously doesn't > workbut potentially does make 'sense'. > Interface IX : 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 > systembut I'm actually not convinced it is as powerful as an OO > onei.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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nicholls, Mark Sent: Wednesday, January 02, 2008 5:41 PM To: haskell-cafe@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 { } 3) Interface IX Where A : IY { } 4) Interface IX : IZ Where A : IY { } I can take a punt at the first 2but then it all falls apart ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
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 dothough 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 where A : IX {} > and > Interface IX 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 allas > interfaces effectively operator on type classes not typeswhich 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 likewhich is obviously problematic in C# it obviously doesn't > workbut potentially does make 'sense'. > Interface IX : 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 > systembut I'm actually not convinced it is as powerful as an OO > onei.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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nicholls, Mark Sent: Wednesday, January 02, 2008 5:41 PM To: haskell-cafe@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 { } 3) Interface IX Where A : IY { } 4) Interface IX : IZ Where A : IY { } I can take a punt at the first 2but then it all falls apart ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell?
Can you give me a summary of why it's meaningless.both would seem to describe/construct values/objectsthey may not be equivalent, but I would expect some considerable overlap. -Original Message- From: Bulat Ziganshin [mailto:[EMAIL PROTECTED] Sent: 02 January 2008 20:29 To: Nicholls, Mark Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? Hello Mark, Wednesday, January 2, 2008, 7:40:31 PM, you wrote: > I'm trying to translate some standard C# constucts into Haskell... some it's meaningless. read http://haskell.org/haskellwiki/OOP_vs_type_classes and especially papers mentioned in the References -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell?
[snip] >-- C#: interface IX1 { String foo1(int); } >class IX1 obj where > foo1 :: Int -> obj -> String Yep...I think that's what I'd dothough I would have done... "foo1 :: obj -> Int -> String" Does that matter? >-- C#: interface IX2 { String foo2(A); } >class IX2 obj a where > foo2 :: a -> obj -> String Ok same here >--C#: interface IX3 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 : IZ where A : IY >class IZ a where {- ... -} >class (IY a, IZ obj) => IX4 obj a where > foo4 :: a -> obj -> String H...this would have been one of my guessesbut let me have a go... >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 look >more like imperative programming. This is finemy 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# interfaces; >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 Haskell, >you can implement an instance of a type class for any datatype! OK but I was going to go onto Interface IX where A : IX { } And Interface IX where A : B { } Where I cannot see a way to do the above in Haskell at allas interfaces effectively operator on type classes not typeswhich seems inherently more powerful But if these could be done in Haskell the see what could be made of stuff likewhich is obviously problematic in C# it obviously doesn't workbut potentially does make 'sense'. Interface IX : A { } >Hope this helps a bit. As I'm new myself to Haskell, so take this with a >"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#, although >C# of course comes with a gigantic .NET framework and tools... I'm looking at Haskell because of the formality of it's type systembut I'm actually not convinced it is as powerful as an OO onei.e. OO ones operatate principally (in Haskell speak) on "type classes" not "types" >Peter -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nicholls, Mark Sent: Wednesday, January 02, 2008 5:41 PM To: haskell-cafe@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 { } 3) Interface IX Where A : IY { } 4) Interface IX : IZ Where A : IY { } I can take a punt at the first 2but then it all falls apart ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell?
I was thinking more along type classesand then I was going to throw some spanners in the works From: Ryan Ingram [mailto:[EMAIL PROTECTED] Sent: 02 January 2008 17:41 To: Nicholls, Mark Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? Of course it depends what's inside the braces, and what you want to do with it, but I'd be inclined to do something like this: 1) data IX a = IX { constructor :: Int -> a, ... } 2) data IX a b = IX { constructor :: Int -> b, func :: a -> b, ... } 3) data IX a b = IX { iy :: IY a, ... } 4) data IX a b = IX { iz :: IZ b, iy :: IY a, ... } Can you specify more clearly what the goal of the conversion is? If you want "OO" style behavior the thing that is most important is existential quantification. -- ryan On 1/2/08, Nicholls, Mark <[EMAIL PROTECTED]> wrote: I'm trying to translate some standard C# constucts into Haskell... some of this seems easy Specifically 1) Interface IX { } 2) Interface IX { } 3) Interface IX Where A : IY { } 4) Interface IX : IZ Where A : IY { } I can take a punt at the first 2but then it all falls apart ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell?
Hello Mark, Wednesday, January 2, 2008, 7:40:31 PM, you wrote: > I'm trying to translate some standard C# constucts into Haskell... some it's meaningless. read http://haskell.org/haskellwiki/OOP_vs_type_classes and especially papers mentioned in the References -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell?
Of course it depends what's inside the braces, and what you want to do with it, but I'd be inclined to do something like this: 1) data IX a = IX { constructor :: Int -> a, ... } 2) data IX a b = IX { constructor :: Int -> b, func :: a -> b, ... } 3) data IX a b = IX { iy :: IY a, ... } 4) data IX a b = IX { iz :: IZ b, iy :: IY a, ... } Can you specify more clearly what the goal of the conversion is? If you want "OO" style behavior the thing that is most important is existential quantification. -- ryan On 1/2/08, Nicholls, Mark <[EMAIL PROTECTED]> wrote: > > I'm trying to translate some standard C# constucts into Haskell... some > of this seems easy > > Specifically > > 1) > > Interface IX > { > } > > 2) > > Interface IX > { > } > > 3) > > Interface IX >Where A : IY > { > } > > 4) > > Interface IX : IZ >Where A : IY > { > } > > > I can take a punt at the first 2but then it all falls apart > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe