3 ms·
> C# has them, and so does Scala. With the slight difference that its generics are reified, so all `Function` generic arities have the same name (it's `Functio
by masklinn 15y ago
> C# has them, and so does Scala.
With the slight difference that its generics are reified, so all `Function` generic arities have the same name (it's `Function<T>`, `Function<T1, T2>`, ...), although because there is no `void` or `Unit` type in C# it needs two base function types, to handle functions with a return value (`Function`) and functions with no return value (`Action`).
I believe the Kotlin project fixes this issue by having a first-class `Unit` type, so C#'s `Action` becomes `Func<Unit>` in Kotlin.
- StrawberryFrog 15y agoC#'s type system is a bit messy over there. Besides Func<T> and Action<T>, there's also Predicate<T> , which works the same as Func<T, bool> except for being an entirely different type that's non-trivial to cast to Func<T, bool>. And the whole lot look a lot like delegates. If they were all just Func<T> (or aliases for that, or wrappers over that when multicast is really needed), it would be a lot simpler.
- jawher 15y agoEven Java has the Void type, meaning you can write: Function<Void> It's a bit shady though as you still have to return a value from the body of the method, and that value has to be null.
- StrawberryFrog 15y agoThat sort of this is also easy to do in C# or any strongly typed language. Similar things in c# are the DBNull type which "Represents a nonexistent value" from a database (http://msdn.microsoft.com/en-us/library/system.dbnull.aspx http://msdn.microsoft.com/en-us/library/system.dbnull.aspx ) and Type.Missing which "Represents a missing value in the Type information"
- masklinn 15y ago> It's a bit shady though 'bit of an understatement there.
- smcj 15y agoThis has nothing to do with each other. Classes with variable generic arities are syntax sugar provided by the C# compiler. Behind your back it will just create Function`0 Function`1 and so on. Seeing how much havoc method overloading creates, I'm fine without this feature. About Kotlin: Before it can fix issues, it should probably start to exist first.