Re: Function minimization and random numbers



Jon Skeet [C# MVP] wrote:
Jon Harrop <usenet@xxxxxxxxxxxxxx> wrote:
In what way does C# lack closures? It supports them in the form of
delegates with captured variables etc. It may not be the same form that
F# uses, but that's not the same thing.

Closures represent all functions but .NET delegates do not because .NET
draws an unnecessary distinction between members and delegates, making
them incompatible. C# inherits this but F# goes to great lengths to
remove this artificial distinction.

It seems to me like *you're* making the artificial distinction here.

C#'s type system makes the distinction, not me.

That is why you must convert a member into a delegate manually in C# when,
in fact, they are both just functions. There's a whole MSDN help page
devoted to this no-op.

You can build closures in C# just fine according to every definition of
closure I've seen.

That's not to say that you can use every member *as* a closure, but to
me that's not the same thing at all.

Then you are retrofitting language features onto Algol with no regard for
what makes them useful. Provided you just want a list of checkboxes of
language features, that's fine, but if you want the features to be useful
then you're going to have to think a lot more about how they interact.

Claiming that C# lacks closures is pure FUD in my view.

Avoid closures if you want to call your F# libraries from C#.

To provide first-class closures, .NET (or C#) might replace all members
with properties that return delegates. Then you could say "C# supports
first-class closures".

No, then you could say "C# supports first-class closures in the same
way that F# does".

That is not how F# supports closures.

Consider a language that support integers but imposes a compile time
distinction between even and odd integers for no logical reason. If that
was the only language you knew, would you back it to the hilt because,
technically, you can work around the type system to use all integers?

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?u
.



Relevant Pages

  • Re: Function minimization and random numbers
    ... lacks closures. ... anonymous functions to delegates. ... There is no loss of static type safety. ... Are you claiming that the C# support for closures is useless? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Function minimization and random numbers
    ... Jon Skeet wrote: ... In what way does C# lack closures? ... Closures represent all functions but .NET delegates do not because .NET ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Function minimization and random numbers
    ... Well, .NET's type system makes the distinction, allowing conversions ... lacks closures. ... design but it culminated in F# rather than delegates. ... Are you claiming that the C# support for closures is useless? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Function minimization and random numbers
    ... Jon Harrop wrote: ... Closures represent all functions but .NET delegates do not because .NET ... then you could say "C# supports first-class closures in the same ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Function minimization and random numbers
    ... Well, .NET's type system makes the distinction, allowing conversions ... Groovy supports overloaded method groups as closures, ... Consider a language that support integers but imposes a compile time ...
    (microsoft.public.dotnet.languages.csharp)