"Duplicate instance declarations"

Hello all why the folowing is not allowed even with all extensions enabled both in Hugs and GHC? class BufStream h where class CharStream h where instance (CharStream h) => BufStream h where class MemoryStream h where instance (MemoryStream h) => BufStream h where i plan to implement many streams, some of which are supporting getBuf/putBuf interface of MemoryStream, and some getChar/putChar interface of CharStream and then automatically derive BufStream using the appropriate operations. but that just fail how can i pass around these restriction? can this be supported in future Hugs/GHC versions? ... just now i encountered this problem again: -- Copy entire contents of Stream to another Stream class (Stream h1, Stream h2) => StreamCopying h1 h2 where copyStream :: h1 -> h2 -> IO () instance (MemoryStream h1, BufStream h2) => StreamCopying h1 h2 where copyStream h1 h2 = return () instance (BufStream h1, MemoryStream h2) => StreamCopying h1 h2 where copyStream h1 h2 = return () -- Best regards, Bulat mailto:bulatz@HotPOP.com

Bulat Ziganshin wrote:
Hello all
why the folowing is not allowed even with all extensions enabled both in Hugs and GHC?
class BufStream h where
class CharStream h where instance (CharStream h) => BufStream h where
class MemoryStream h where instance (MemoryStream h) => BufStream h where
Try this: class (BufStream h) => CharStream h where class (BufStream h) => MemoryStream h where

Hello Ashley, Wednesday, December 28, 2005, 1:56:51 AM, you wrote:
instance (CharStream h) => BufStream h where instance (MemoryStream h) => BufStream h where
AY> Try this: AY> class (BufStream h) => CharStream h where AY> class (BufStream h) => MemoryStream h where thank you, that will work, although it is not what i exactly want. in the ideal, i want to derive from any of these 3 classes other two. but it seems that i need to establish some ordering between them -- Best regards, Bulat mailto:bulatz@HotPOP.com

Hello Ashley, Wednesday, December 28, 2005, 1:56:51 AM, you wrote: i tried to implement your solution and failed. i will extend my original example to show you my problem:
class BufStream h where vPutBuf :: h -> Ptr a -> Int -> IO ()
class CharStream h where vPutStr :: h -> String -> IO ()
instance (CharStream h) => BufStream h where vPutBuf h buf len = do str <- peekCStringLen (castPtr buf, len) vPutStr h str
class MemoryStream h where instance (MemoryStream h) => BufStream h where
AY> Try this: class BufStream h where vPutBuf :: h -> Ptr a -> Int -> IO () class (BufStream h) => CharStream h where vPutStr :: h -> String -> IO () now i can give default implemetation of `vPutStr` via `vPutBuf`. but i need to implement `vPutBuf` via `vPutStr`! AY> class (BufStream h) => MemoryStream h where the same problem here - i need to implement `vPutBuf` via functions of MemoryStream, but it's impossible -- Best regards, Bulat mailto:bulatz@HotPOP.com
participants (2)
-
Ashley Yakeley
-
Bulat Ziganshin