|
![](/i/fill.gif) |
On 14/03/2013 08:24 PM, Warp wrote:
> Orchid Win7 v1<voi### [at] dev null> wrote:
>> Again, the problem is that we need to write a method which examines TWO
>> objects which must be of THE SAME class.
>
> I don't understand at all what that even means.
>
> Start by explaining (briefly) what "examines" means in this context.
Consider another example: Let's say you want to do something like
public abstract class Tree
{
...
public abstract Tree Union(Tree other);
...
}
So we can now write SplayTree, HeapTree, SearchTree, etc as subclasses
of Tree. But the thing is... you can only Union() two trees together if
they are THE SAME TYPE of tree. So you can take the union of two
SplayTrees, or the union of two HeapTrees, but NOT the union of a
SplayTree and a HeapTree.
But the type signature above does not express this constraint. It says
that you can union *any* two objects so long as they are both Trees -
which is wrong.
That's the basic problem with writing a monad interface in C# (or Java,
for that matter). You could do a run-time type check and throw an
exception if the types don't match, of course. But I haven't yet figured
out how to enforce the constraint at compile-time.
(Having asked some questions on stack overflow, it appears it might
actually be possible in C# though... I'll give it a go tomorrow.)
Post a reply to this message
|
![](/i/fill.gif) |