On Wednesday, 4 December 2013 at 08:24:03 UTC, qznc wrote:
On Wednesday, 4 December 2013 at 01:53:39 UTC, Shammah
Chancellor wrote:
Or is D syntax not generic enough to define monads?
I started to port monads to D [0]. You can do it, but it looks
ugly. The trick is to implement (Haskell) type classes via
template specialization. I came to the conclusion that it is
not worth it.
What D kind of lacks is a way to define a general type class
aka the interface. Of course, you could use the "interface"
keyword, but then you cannot apply it to structs. Haskell has
no structs (value type records), so they do not have this
problem. Look at how isInputRange is implemented [1]. The
traits in Rust [2] provide this interface mechanisms as a
language feature. D uses static-if instead.
D uses static if and template constraints for typeclass/concept
checking because one cannot add specializations to templates
defined in other modules. Using template specialization for
defining type class instances would render them not extensible
for users