|
|
Invisible wrote:
> * This is why, if a Haskell function takes any functions as arguments,
> they invariably come *first*, and any data structures come *last*. ;-)
Technically, I would think you could have a curried function in a language
with named parameters pretty easily. It wouldn't have to be the first
argument as long as you're making up a new language anyway. It would
actually just wind up being the same kind of syntactic sugar that default
parameters are.
> I don't know anything about it.
They're just three different syntaxes for exactly the same thing, as the
compiler evolved through different releases.
> I've only seen "delegates" in other
> languages, where they're used because "callback functions are really
> useful, but we don't want actual function pointers, so..."
One difference is that a delegate can point to either a static function, or
to a instance function with its associated instance. So if you have a
delegate xyz that takes a float and returns an int, you can have
xyz = my_static_function;
xyz = some_instance.instance_method;
Also, delegates are really lists of such pointers, and invoking it calls
each one in turn. Your basic Observer pattern.
>> Lambda expressions are darned convenient. I used them in my little FFT
>> toy app:
>>
>> RealInput.Data = GenerateWave(x => cos((Math.Pi*2*x)/(DataLen-1)));
>
> They're also damned useful when you want to curry a function:
> bar = foo (...my random lambda function that I only just here...)
That's where they're used in C#.
Note too that depending on the declaration of the argument you're passing
the function to, your lambda expression in C# can actually wind up being a
syntax tree instead of a function with actual machine code. So you can
write a routine that takes an AST, frobs it around to make a new AST,
compiles it, and runs it. This is how the mechanisms for querying SQL from
C# work - you can write something like
db.table["customers"].select(x => x.Name > "Henry")
and the "select()" function takes the AST describing that condition,
translates it to SQL, and sends it to the database.
>> FooBarBaz fb = new FooBarBaz() { foo = 123, bar = 4.56 };
>> Baz takes on the default value of "" (assuming its a string)
My understanding is that only works with properties. And of course Baz gets
whatever the constructor sets it to, rather than necessarily an empty
string. (Anyway, wouldn't it get null if not set?)
--
Darren New, San Diego CA, USA (PST)
"Ouch ouch ouch!"
"What's wrong? Noodles too hot?"
"No, I have Chopstick Tunnel Syndrome."
Post a reply to this message
|
|