Re: Re: [Haskell-cafe] Problem with result-type context restrictions in typeclasses.

2009-09-30 Thread Alexander Dunlap
I think instance Bar (Ret c) => Foo c where ... will do what you are asking. Alex On Tue, Sep 29, 2009 at 10:25 PM, DNM wrote: > > Dan, thanks again for the response. > > I changed my code to use type families to let each Cls instance (actually a > more complicated instance in my code) deter

Re: Re: [Haskell-cafe] Problem with result-type context restrictions in typeclasses.

2009-09-30 Thread Ryan Ingram
You can require the associated type to have a particular instance, like this: class (Bar (Ret c)) => Cls c where type Ret c foo :: c -> Ret c Another option is to use existential types: data HasBar = forall a. Bar a => HasBar a class Cls c where foo :: c -> HasBar You then have to wr

Re: [Haskell-cafe] Problem with result-type context restrictions in typeclasses.

2009-09-30 Thread Miguel Mitrofanov
class Cls c where type Ret c :: (Bar *) => * -- or a better name foo :: c -> Ret c which isn't legal Haskell. OK, that's exactly the same thing I've met when developing compose-trans. I needed guarantees that something is a Monad. My way of doing that was to make "Bar" ("Monad" in my c

Re: Re: [Haskell-cafe] Problem with result-type context restrictions in typeclasses.

2009-09-29 Thread DNM
Dan, thanks again for the response. I changed my code to use type families to let each Cls instance (actually a more complicated instance in my code) determine which Bar instance type it will return, but this didn't seem to work. The problem is that the client of the typeclass instance methds ('