On Tuesday 14 September 2004 18:18, Heribert.Schuetz.extern@HVB.de wrote:
* Can't much of the simplicity of the Haskell code also be reached by just switching from C++ to something like Java or C#? (Probably an example from the application domain will be most convincing. So I probably have to bite the bullet and reimplement some code in Java or C#. But if you have some examples, they might be helpful.
I don't have examples but I've been working with C# 8 hours per day for 6 months and I ensure you that no, they are not simple. C++ is simpler for enterprise uses than C#, IMHO, because you fundamentally reuse other people libraries and so worry _less_ about memory management than you'd expect, but YMMV. On the other hand, C# has NO parametric polymorphism and after a while I've begun to miss C++ templates. C# has functional programming, they say, but no you can't use a method name as a function. You first have to create an "event". Composing this with the absence of parametric polymorphism and type inference, here's what a _monomorphic_ "map" function looks like, with a possibly naive syntax because I don't have the compiler handy (and worked 8 hours today,too). ///// public delegate int myDelegate(int i); //This is a type declaration public ArrayList map(myDelegate fn,ArrayList list); // Note that the list is untyped, but the function is strongly typed. { ArrayList result = new ArrayList(); foreach (Object obj in list) { result.Add(fn(obj)); } return result; } ///// 6 rows of effective code, untyped, contrived and poorly reusable. And this is the way you call it (you already know, ok, but now I am having fun :)) public int increment(int i) { return i+1; } map(new myDelegate(increment),myList); // note the call to "new" The map function from the haskell prelude: map f xs = [f x | x <- xs] and how you call it: map (\ x -> x+1) myList It's strongly typed, polymorphic and reusable. And it's far more readable and clear in intent, too. Do I need to say more? If you have the possibility to use haskell, ocaml or SML at work, do so :) OK, I realize that you already knew haskell, but you asked first :) Vincenzo