4 ms·
Higher kinds are quite nice. 1. In scala you could write class MyClass[A[_]](a: A) and it can only take a 'container' (List/Future/Option). in C#/F# thi
by runT1ME 13y ago
Higher kinds are quite nice.
1. In scala you could write
class MyClass[A[_]](a: A)
and it can only take a 'container' (List/Future/Option).
in C#/F# this is invalid:
class MyClass<A<?>> {
public MyClass(A a) {
}
}
You could make a plain ol' generic that took a concrete type List<Int> but not just on the type.
2. Implicit Conversion: In C#/F# you get extension methods, but it doesn't help you take an existing class and ad-hoc make it implement an interface.
So in scala I could do this:
trait XMLSerializable {
def toXML(): XMLNode
}
and then let's say I want to make existing classes in the standard library implement this interface:
implicit def toXMLSerializable(li: List[_]): XMLSerializable =
new XMLSerializable {
def toXML = {
transformListToXML(li)
}
}
I can now do:
val genericXmlSerializable: XMLSerializable = List[Int](1,2,3,4)