Monad and its little sisters

qznc qznc at go.to
Thu May 16 04:56:46 PDT 2013


I implemented the Maybe monad using template specialization. 
Feedback welcome!

https://bitbucket.org/qznc/d-monad/src/ba39f2551af0e2e90a40653af92c048fed519a18/generic.d?at=master

However, a few questions or possibly shortcomings of D came up.

1. I could not specify the inheritance between the templates. A 
Monad is an Applicative, which is a Functor. Is there some 
template magic to check "There is a template like this 
'Functor!Maybe'"?

2. A template cannot restrict template specializations. 
Specifically, the Functor(T) template should restrict 
Functor(T:Maybe), such that it must declare functions or 
templates of a specific signature.

3. Shouldn't a function be a delegate? I assume this question 
came up before, but there seems to be interest to make it easier. 
My code specifies function parameters three times. It should be a 
delegate and the caller should use std.functional.toDelegate to 
convert it. Why not an implicit cast? Performance seems to be the 
only problem.


More information about the Digitalmars-d-learn mailing list