[Hugs-users] Re[2]: [Haskell-cafe] bug in WinHugs Version 20051031?

Bulat Ziganshin bulatz at HotPOP.com
Fri Jan 6 10:48:24 EST 2006


Hello Ross,

Friday, January 06, 2006, 2:16:24 PM, you wrote:

>> the following program fails to load in Hugs2005 with all Haskell
>> extensions enabled:
>> 
>> instance (CharStream m h) => ByteStream m h where ...
>> instance (ByteStream m h) => CharStream m h where ...

RP> Looks circular to me, i.e. there's no justification for inferring
RP> instances of either class.  However recent GHC's spot the recursion
RP> in such cases and create mutually recursive instances.

the following definition, which is a pure H98, also looks circular:

class Something x where
  a::Int
  b::Int
  a = b+1
  b = a-1

nevertheless, its semantics are well-known and obvious - instance need
to define either a or b, and another function will be automatically
derived. my instances definitions are just the same - you can define
either functions in one class or in another, and then derive
definitions for another class. i can't use single-class solution,
because in actual code there are 4 different classes and in ideal
someone can give explicit definition only for functions in one class
and all other definitions must be derived automatically:

class ByteStream s where getByte::Int
class CharStream s where getChar::Char
class BlockStream s where getBuf::Ptr a
class MemoryStream s where receiveBuffer::Ptr a

instance (ByteStream s) => CharStream s where
  getChar = chr getByte
....

instance BlockStream Handle where ....
instance CharStream StringBuffer where ....
instance MemoryStream MemoryBuffer where ....


-- 
Best regards,
 Bulat                            mailto:bulatz at HotPOP.com





More information about the Hugs-Users mailing list