Understanding Type Classes, Scala implicit and C# -
i read blog post joe duffy haskell type classes , c# interfaces.
i'm trying understand have enabled c# have type classes, , wonder whether feature scala's implicits solve it?
having kind of feature enable writing this:
public interface ireducableof<t> { t append(t a, t b); t empty(); } public t reduce(this ienumerable<t> vals, **implicit** ireducerof<t> reducer ) { enumerable.aggregate(vals, reducer.append); }
making sure have in our context implementation of ireducerof<t>
compiler "just" pick reducer , use execute code.
of course, code cannot compile.
but questions are:
can enable implementing type classes?
is similar happening in scala?
i'm asking general understanding , not particular problem.
update
i've encountered github repo on possible implementation of type classes in c#
yes, how type classes implemented in scala. general design principle in scala add general , re-usable features language can used implement higher-level constructs library constructs, if @ possible. in particular case, type classes can implemented using objects , implicits, both objects , implicits have uses beyond merely implementing type classes, makes more sense include more general building blocks in language , allow users build higher-level constructs (like type classes) on top.
the canonical paper on implementing type classes objects , implicits aptly named type classes objects , implicits bruno c. d. s. oliveira, adriaan moors, , martin odersky. there's nice discussion of paper on lambda-the-ultimate.
note adding implicits language not enough. implement type classes way, lot of "interesting" type classes (such monad
) cannot expresses in c♯: monad
higher-kinded, c♯'s type system not.
Comments
Post a Comment