Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-12 Thread John Meacham
On Sun, Dec 11, 2005 at 07:41:43PM +, Ben Rudiak-Gould wrote: I think the problem is not with the use of forall, but with the use of the term existential type. The fact that existential quantification shows up in discussions of this language extension is a red herring. Even Haskell 98

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-11 Thread Ben Rudiak-Gould
John Meacham wrote: PS. many, including me, feel 'forall' is a misnomer there and should be the keyword 'exists' instead. so just read 'foralls' that come _before_ the type name as 'exists' in your head and it will make more sense. I disagree. When you write forall a. D (P a) (Q a) it

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread Tomasz Zielonka
On Wed, Dec 07, 2005 at 04:09:31PM -0800, John Meacham wrote: you arn't using existential types here. an example with an existential type would be (in ghc syntax) data forall a . State = Start | Stop | (Show a, Eq a) = State a Shouldn't it be: data State = Start

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread John Meacham
On Thu, Dec 08, 2005 at 09:13:10AM +0100, Tomasz Zielonka wrote: Shouldn't it be: data State = Start | Stop | forall a . (Show a, Eq a) = State a ah. you are right. my bad. John -- John Meacham - ⑆repetae.net⑆john⑈ ___

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread Joel Reymont
Did someone actually try compiling this? Here are the results: data State a = Start | Stop | (Show a, Eq a) = State a deriving Show foo.hs:1:5: Can't make a derived instance of `Show (State a)' (`State' has existentially-quantified constructor(s)) When deriving

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread Joel Reymont
On Dec 8, 2005, at 12:09 AM, John Meacham wrote: if you are okay with a being an argument then data State a = Start | Stop | State a deriving(Show,Eq) will do what you want I believe. This does the trick! Thank you! -- http://wagerlabs.com/

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread Joel Reymont
Here is something else that I don't quite understand... Original version compiles: push :: Show b = State b - Dispatcher b a - (ScriptState a b) () push state dispatcher = do w - get trace 95 $ push: Pushing ++ show state ++ onto the stack let s = stack w putStrict $

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread Cale Gibbard
data (Eq a, Show a) = State a = Start | Stop | State a deriving Show Putting the class context on the data constructor like that wasn't doing you any more good than this way, and was causing ghc to think that the constructor was existentially quantified. - Cale On 08/12/05, Joel Reymont [EMAIL

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread Cale Gibbard
Okay, so here you *did* get something from the existential typing :) The type of show, restricted to State in the original version is: show :: Show a = State a - String Now, in the new version, you get the type: show :: (Eq a, Show a) = State a - String because what happens is that pattern

Re[2]: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread Bulat Ziganshin
Hello Joel, Thursday, December 08, 2005, 12:26:52 PM, you wrote: JR I was also hoping that something like this would let me avoid JR quantifying a in functions downstream but alas, it does not happen. I JR have to use (Eq a, Show a) = a ... everywhere else. to avoid context declarations you

Re: Re[2]: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread Joel Reymont
Doesn't this have an effect on performance? Is GHC still able to optimize things properly? On Dec 8, 2005, at 10:20 AM, Bulat Ziganshin wrote: Hello Joel, Thursday, December 08, 2005, 12:26:52 PM, you wrote: JR I was also hoping that something like this would let me avoid JR quantifying a

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread Benjamin Franksen
On Thursday 08 December 2005 09:36, John Meacham wrote: On Thu, Dec 08, 2005 at 09:13:10AM +0100, Tomasz Zielonka wrote: Shouldn't it be: data State = Start | Stop | forall a . (Show a, Eq a) = State a ah. you are right. my bad. But this is a rank-2 type, not an

Re[4]: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread Bulat Ziganshin
Hello Joel, better to ask Simon. if automatically determined type is more generic than you really need, this can something slow program. but i think that generally this have no big impact, because many functions are just inlined and, theoretically, can be specialized just at inlining place

[Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-07 Thread Joel Reymont
Folks, Is there a less verbose way of doing this: data State a = Start | Stop | (Show a, Eq a) = State a instance Eq a = Eq (State a) where (State a) == (State b) = a == b Start == Start = True Stop == Stop = True instance Show a = Show (State a) where show (State

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-07 Thread Greg Buchholz
Joel Reymont wrote: Folks, Is there a less verbose way of doing this: data State a = Start | Stop | (Show a, Eq a) = State a I'm curious, what is the difference between the above and... data State a = Start | Stop |

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-07 Thread John Meacham
On Wed, Dec 07, 2005 at 10:12:07PM +, Joel Reymont wrote: data State a = Start | Stop | (Show a, Eq a) = State a you arn't using existential types here. an example with an existential type would be (in ghc syntax) data forall a . State = Start | Stop | (Show

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-07 Thread Bulat Ziganshin
Hello Joel, Thursday, December 08, 2005, 1:12:07 AM, you wrote: JR Is there a less verbose way of doing this: data (Show a, Eq a) = State a = Start | Stop | State a deriving (Show, Eq) -- Best regards, Bulatmailto:[EMAIL PROTECTED]