ML Versus C#
JoshuaTauberer wanted to take a moment to comment on how C# should be able to do all of the things that ML can. I may end up describing my ideal language, tho...
(This is a work in progress. Feel free to start an argument here.)
Syntax
Come on. Why use weird symbols that don't correspond to how they're used in plain English? What are those asterisks doing? And haven't we learned to spell things out? "fun"?
Brackets are used to delineate block structure in plain English? I could go on, but the comparison to English is just ridiculous. -- AdamChlipala
Yes, we use parenthesis quite often (like here) to group things, and commas (not asterisks if I understood the syntax right) to separate things.
You didn't understand the syntax right. Asterisks are used as standard ASCII notations for the mathematical symbol for Cartesian product, which is itself absolutely standard in all areas of math. The language of math is much more suited for programming than natural languages. -- AdamChlipala
Type Safety
ML is more type-safe than C#, sure. But, once C# gets generics, whatever type safety ML has over C# is going to play a minimal role in creating more stable programs. The only widespread instance that I'm aware of of potentially unsafe type-casting is when iterating through C#'s collections. And, even then, I've never had the problem myself of putting the wrong type of object in a list.
So, kudos to ML for being perfectly type-safe, but it just doesn't make programming much better over the type of type-safety elsewhere.
It's too functional
Programs do things. Side effects are a fact of life outside of the computer scientist's cubicle. Relegating side effects to the dark side just sends the wrong impression about ML to programmers who have outputs and GUIs in mind.
Many problems are most easily formulated functionally. You shouldn't be so glib without any experience yourself and without any concrete reasons. -- AdamChlipala
And many problems are most easily understood imperatively. I'd like to see a good analysis of this - link anyone?
It's ridiculous of you to ask for this when you have made no effort to learn functional programming. I would think that you would understand by now how much of coding knowledge must be learned by experience. -- AdamChlipala
Garbage Collection
They're both garbage collected. All modern languages are, so this is hardly a unique point to ML.
Tuples
ML has tuples that simplify return types. This is most definitely lacking in C#.
Presumably this will sort of be able to be done in C# once generics are introduced: Pair<float,string>, Triple<string,int,float>, etc. Can't imagine why you'd want to return more than three things at once without a class/struct anyway. But, enums that are used for just one function, and can be defined in-place, would be great.
Type Inference
ML's type inference hides what's going on. For instance:
fun incrementFirst(x, y) = (x + 1, y)
ML infers that x must be an integer because you add 1 to it. I don't want the compiler infering anything. If x has to be an integer, I want it to be because I said so.
You are free to include type annotations anywhere you please in your programs. Type inference is a time-saving feature that you probably can't appreciate because of how small type descriptions are in the weak type systems to which you are accustomed. -- AdamChlipala
And if I'm not the author of the code and I want to understand it, then I have to carry out the type inferences mentally.
It's very easy to understand. Your statement is of the same type as "But if I didn't write this C code, then I will have to go find a variable's declaration to know its type!" Yes, that's correct, and no, it's not hard to do. You just have no experience whatsoever with type inference or pretty much anything found in ML but not Java. -- AdamChlipala
Parametric Polymorphism
Parametric polymorphism in ML is very interesting from the point of view of an OO programmer.
Let's say I have three types of things -- colors, shapes, and sizes -- and each has a behavior in common, such as getting the name of the thing. Then, in OO I have a class for each, and each class defines its name behavior. This structure is good if I later want to add an orientation class, I can specify its name behavior inside the new class without having to touch any old code.
In ML, it seems to be the other way around. A function is to return the name of the object passed to it. How it computes the result depends on its argument, so the function is defined separately for each argument type. The benefit here is if I add a new argument type, I can add the new name function along side the others, so they're all together.
Maybe a language should be able to do both? (Can ML do both?)
You have completely misunderstood parametric polymorphism. Read MlLanguage again. -- AdamChlipala.
First-Class Functions and Lexical Closures
C# is getting syntactic sugar to emulate those. I conceed, not as good as ML's.
Maybe it's just me but I think that a more conventional text describing C# features and a bit of advocacy would have been preferable to this direct confrontation C# vs. ML. This has been discussed many times on the forums and it's unlikely that we will agree on what is the best language. I think that the goal of this wiki should be to give the most information possible on different subjects (in this case computer language) so that the user have the best possible information to make the best choice. Let's try to stay objective even if it's hard sometimes.
This page is meant to help people make an informed decision, not come to the conclusion that one language is better than the other.
Phrases like "It's Too Functionnal" really sound like a judgement agaist ML to me. Perhaps it's just my opinion of course. If it gets into language war, I will quickly loose interrest in this wiki.
