
20 Apr
2006
20 Apr
'06
2:07 p.m.
Bulat Ziganshin wrote:
i'm tried to say that there is no such dynamic beast as virtual functions in C++
I think you can use existential types to simulate virtual functions: -- 'a' is a stream of b's class StreamClass a b where get :: a -> IO b -- hide the particular 'a' to get any stream of b's data Stream b = forall a. StreamClass a b => Stream a -- a concrete 'a' data TextStream = ... instance StreamClass TextStream Char where get ... -- another concrete 'a' instance StreamClass MemoryStream Char where get ... -- concrete 'a' is hidden just as in C++ virtual dispatch useStream :: Stream b -> IO b useStream (Stream x) = get x -- because x satisfies StreamClass x b Regards, Brian.