
Matthias Fischmann wrote:
is there any difference between these two? if they are equivalent, why the two different ways to say it?
data X where X :: (Resource a) => a -> X data Y = forall a . (Resource a) => Y a
There's no difference. There are two ways to say it for historical reasons. The second notation dates back many years, while the first notation is new and experimental. Only the first notation supports GADTs, and only the second supports deriving declarations and strict fields and record syntax (though I think this is going to change). Also the second notation is more convenient when you're declaring an ordinary datatype---compare data List a = Nil | Cons a (List a) data List a where { Nil :: List a ; Cons :: a -> List a -> List a }
and now it gets interesting: i need instances for Rs on Show, Read, Eq, Ord. Show is very simple, but Read?
I think you're right: it's impossible to implement Read for Rs in an extensible way, because there's no way to obtain the necessary Resource dictionary at runtime. I've wished in the past for a family of functions, one for each single-parameter typeclass, with types something like Dynamic -> (forall a. C a => a -> b) -> Maybe b and you'd need something similar here. Assuming this is indeed impossible and you have to close the world of Resources, you may as well do it by writing data Rs = RsRice Rice | RsCrudeOil CrudeOil | ... deriving (Show,Read,Eq,Ord) -- Ben