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.
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to