Re: [Haskell-cafe] object oriented technique

2011-03-31 Thread Tad Doxsee
Tillmann, Thank you for your detailed reply. It was a real eye opener. I hadn't seen anything like that before. It seems that your ShapeClass is very similar to, and plays the same role as, the Class ShapeC from my example. I wonder if that was how haskellers implemented shared functions

Re: [Haskell-cafe] object oriented technique

2011-03-30 Thread Gábor Lehel
On Wed, Mar 30, 2011 at 6:52 AM, Tad Doxsee tad.dox...@gmail.com wrote: Greg, Thanks for your help.  Is there any significant difference between using existential quantification data ShapeD = forall s. ShapeC = ShapeD s versus a GADT data ShapeD  where  ShapeD :: ShapeC s = s - ShapeD

Re: [Haskell-cafe] object oriented technique

2011-03-30 Thread Tillmann Rendel
Hi, Steffen Schuldenzucker wrote: data Shape = Shape { draw :: String copyTo :: Double - Double - Shape } Tad Doxsee wrote: Suppose that the shape class has 100 methods and that 1000 fully evaluated shapes are placed in a list. The above solution would store the full method table

Re: [Haskell-cafe] object oriented technique

2011-03-30 Thread Gregory Collins
On Wed, Mar 30, 2011 at 6:52 AM, Tad Doxsee tad.dox...@gmail.com wrote: Greg, Thanks for your help.  Is there any significant difference between using existential quantification data ShapeD = forall s. ShapeC = ShapeD s versus a GADT data ShapeD  where  ShapeD :: ShapeC s = s - ShapeD

Re: [Haskell-cafe] object oriented technique

2011-03-29 Thread Tako Schotanus
Hi, just so you know that I have almost no idea what I'm doing, I'm a complete Haskell noob, but trying a bit I came up with this before getting stuck: class Drawable a where draw :: a - String data Rectangle = Rectangle { rx, ry, rw, rh :: Double } deriving (Eq, Show)

Re: [Haskell-cafe] object oriented technique

2011-03-29 Thread Tako Schotanus
Sorry , the following line got lost in the copy paste: {-# LANGUAGE ExistentialQuantification #-} -Tako On Tue, Mar 29, 2011 at 11:09, Tako Schotanus t...@codejive.org wrote: Hi, just so you know that I have almost no idea what I'm doing, I'm a complete Haskell noob, but trying a bit

Re: [Haskell-cafe] object oriented technique

2011-03-29 Thread Steffen Schuldenzucker
Tad, It doesn't look bad, but depending on what you want to do with the [ShapeD] aftewards you might not need this level of generality. Remember that the content of a ShapeD has type (forall a. ShapeC a = a), so all you can do with it is call class methods from ShapeC. So if all you do is

Re: [Haskell-cafe] object oriented technique

2011-03-29 Thread Yves Parès
Actually, Tako: data Shape = forall a. Drawable a = Shape a Can also be done with GADTs: data Shape where Shape :: Drawable a = a - Shape If wouldn't know if one approach is preferable to the other or if is just a matter of taste. Your problem, Tad, is kind of common. I ran

Re: [Haskell-cafe] object oriented technique

2011-03-29 Thread Yves Parès
Actually, after thinking it back, I found out one other method. The key idea is to split what is common to every shape with what is not: data Circle = Circle { cr :: Double } data Rectangle = Rectangle { rw, rh :: Double } class Shapeful s where name :: s - String fields :: s - String

Re: [Haskell-cafe] object oriented technique

2011-03-29 Thread Lyndon Maydwell
Should that be inner :: s? data Shape = forall s. (Shapeful s)   = Shape { sx, sy :: Double, inner  :: a } ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] object oriented technique

2011-03-29 Thread Tad Doxsee
Greg, Thanks for your help.  Is there any significant difference between using existential quantification data ShapeD = forall s. ShapeC = ShapeD s versus a GADT data ShapeD  where  ShapeD :: ShapeC s = s - ShapeD I'm not sure I understood what you meant by You don't need to write more

Re: [Haskell-cafe] object oriented technique

2011-03-29 Thread Tad Doxsee
Hi Steffen, Thanks for your answer. It was very helpful. Suppose that the shape class has 100 methods and that 1000 fully evaluated shapes are placed in a list. In this unlikely scenario, would your suggested technique require more memory than the GADT technique, because each instance of the

Re: [Haskell-cafe] object oriented technique

2011-03-29 Thread Tad Doxsee
Hi Tako, The link to http://www.haskell.org/haskellwiki/Existential_type was very helpful and gave examples very similar to the answers I received from the haskell-cafe contributors. Thanks, Tad On Tue, Mar 29, 2011 at 2:12 AM, Tako Schotanus t...@codejive.org wrote: Sorry , the following