Re: Function minimization and random numbers
- From: Jon Harrop <usenet@xxxxxxxxxxxxxx>
- Date: Thu, 07 Feb 2008 02:05:05 +0000
Jon Skeet [C# MVP] wrote:
Jon Harrop <usenet@xxxxxxxxxxxxxx> wrote:
It seems to me like *you're* making the artificial distinction here.
C#'s type system makes the distinction, not me.
Well, .NET's type system makes the distinction, allowing conversions
between them.
Exactly.
However, that seems irrelevant in terms of the question of whether C#
lacks closures. You claim that it does, and I'll ask again: please
provide some widely accepted definition of "closure" which C# doesn't
satisfy.
Delegates are second class constructs, incompatible with other kinds of
functions (members) due to the problem you just described.
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.
What exactly do you mean by "manually"?
The programmer has to do something: the task is not automated by the
compiler.
Do you mean there has to be an
appropriate delegate type to convert to? That's certainly true. I don't
see the issue though - unless you want to do away with static type
safety, there has to be something available to encapsulate the
signature of the function.
You only need a single generic function type:
'a -> 'b
There is no loss of static type safety.
Now, you could well want to do away with the static type safety -
I want a more expressive type system that offers more static type safety.
Groovy supports overloaded method groups as closures, where the
appropriate method to actually call is determined at execution time,
for example. There are advantages and disadvantages to that - but I
haven't seen anything in a definition of closures which *requires* a
dynamic interface.
There are lots of statically-typed functional programming languages: OCaml,
SML, Haskell, F#.
Anonymous methods and lambda expressions were added with no thought
whatsoever.
On the contrary, Microsoft have put a lot of thought into their language
design but it culminated in F# rather than delegates. :-)
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.
Are you claiming that the C# support for closures is useless? That
would rule out most of LINQ to start with...
Relegating functions to second-class citizens makes functional programming
unnecessarily tedious.
Claiming that C# lacks closures is pure FUD in my view.
Avoid closures if you want to call your F# libraries from C#.
So has F# eschewed the standard .NET use of delegates as effectively
function pointers? If F# really doesn't allow the use of what *the
whole of the rest of .NET* treats as functions to be treated as
functions, that sounds like F#'s fault rather than C#'s. However, I
seem to remember that actually you *can* use delegates in F# perfectly
easily. I'd check with Robert's book, but it's at work at the moment.
F# programs can define and use delegates but F#'s closures are not
delegates.
Perhaps you'd deign to explain to us mere peasants just why F#'s
support of closures is so wonderful as to make C#'s support appear to
be useless and to even count as a lack of support in your (previously
stated) view.
Look at parser combinators, for example.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?u
.
- Follow-Ups:
- Re: Function minimization and random numbers
- From: Jon Skeet [C# MVP]
- Re: Function minimization and random numbers
- References:
- Re: Function minimization and random numbers
- From: Jon Harrop
- Re: Function minimization and random numbers
- From: Marc Gravell
- Re: Function minimization and random numbers
- From: Jon Harrop
- Re: Function minimization and random numbers
- From: Marc Gravell
- Re: Function minimization and random numbers
- From: Jon Harrop
- Re: Function minimization and random numbers
- From: Jon Skeet [C# MVP]
- Re: Function minimization and random numbers
- From: Jon Harrop
- Re: Function minimization and random numbers
- From: Jon Skeet [C# MVP]
- Re: Function minimization and random numbers
- From: Jon Harrop
- Re: Function minimization and random numbers
- From: Jon Skeet [C# MVP]
- Re: Function minimization and random numbers
- Prev by Date: Re: Generic object manipulation
- Next by Date: Re: Saving the lsitbox items state in database
- Previous by thread: Re: Function minimization and random numbers
- Next by thread: Re: Function minimization and random numbers
- Index(es):
Relevant Pages
|