Re: [Haskell-cafe] Inheritance and Wrappers

2011-02-03 Thread Ozgur Akgun
On 3 February 2011 02:35, Brandon Moore wrote: > Here's one thing to consider: > > Can you write a function > > f :: (Data a) => a -> String > f x = termTag x > > It would seem the Data a => Term a instance justifies > this function, and it will always use the default instance. > > Now, what happ

Re: [Haskell-cafe] Inheritance and Wrappers

2011-02-02 Thread Brandon Moore
>OK, what about this as a use case then. I want to create a type class 'Term' >with only one function in it. The function returns a 'termTag' which labels >the >"kind" of a value in a DSL. > >class Term a where > termTag :: a -> String > > >A user of this type-class can happily provide an

Re: [Haskell-cafe] Inheritance and Wrappers

2011-02-01 Thread Stephen Tetley
On 1 February 2011 12:45, Ozgur Akgun wrote: > I am not very much interested in the technical details about how things > currently are, I am more interested in a discussion about why (if?) this > would be considered a design flaw? Wanting a general base case + specific exceptional cases is in no

Re: [Haskell-cafe] Inheritance and Wrappers

2011-02-01 Thread Daniel Fischer
On Tuesday 01 February 2011 13:45:34, Ozgur Akgun wrote: > I want to be able to write the following instance to accomplish that: > > instance Data t => Term t where >     termTag = show . toConstr > > And if the user wants to write a more specific instance, they should be > welcome to do so: > > in

Re: [Haskell-cafe] Inheritance and Wrappers

2011-02-01 Thread John Lato
On Tue, Feb 1, 2011 at 11:47 AM, Ozgur Akgun wrote: > On 1 February 2011 11:41, John Lato wrote: > >> The important point is that this declares an AbGroup instance for every >> type, not just types with Num instances. >> > > So, is there a way to declare an AbGroup instance for the types with nu

Re: [Haskell-cafe] Inheritance and Wrappers

2011-02-01 Thread Ozgur Akgun
OK, what about this as a use case then. I want to create a type class 'Term' with only one function in it. The function returns a 'termTag' which labels the *"kind"* of a value in a DSL. class Term a where termTag :: a -> String A user of this type-class can happily provide an instance without

Re: [Haskell-cafe] Inheritance and Wrappers

2011-02-01 Thread Stephen Tetley
On 1 February 2011 11:47, Ozgur Akgun wrote: > > So, is there a way to declare an AbGroup instance for the types with num > instances only? No - as Henning says its then no more useful than simply a function: add :: (Num u) => a -> a -> a add = (+) 'Overarching instances' i.e. classes with one

Re: [Haskell-cafe] Inheritance and Wrappers

2011-02-01 Thread Ozgur Akgun
On 1 February 2011 11:41, John Lato wrote: > The important point is that this declares an AbGroup instance for every > type, not just types with Num instances. > So, is there a way to declare an AbGroup instance for the types with num instances only? Thanks, Ozgur __

Re: [Haskell-cafe] Inheritance and Wrappers

2011-02-01 Thread John Lato
> > From: Steffen Schuldenzucker > > On 01/31/2011 08:58 PM, MattMan wrote: > > [...] > > > > data Wrapper a = Wrap a > > instance (Num a) => AbGroup (Wrapper a) where > > add (Wrap i) (Wrap j) = Wrap(i+j) > > > > However, this is clumsy. Is there something else I can do? Thanks > This is

Re: [Haskell-cafe] Inheritance and Wrappers

2011-01-31 Thread MattMan
<\quote> Henning Thielemann wrote: > > If all methods of AbGroup can be defined for all Num types - why do you > want an AbGroup at all? You could simply write functions with Num > constraint. > > Well, I'd rather not have to implement (*), abs, etc on every abelian group. You may be also

Re: [Haskell-cafe] Inheritance and Wrappers

2011-01-31 Thread Henning Thielemann
On Mon, 31 Jan 2011, Brandon S Allbery KF8NH wrote: On 1/31/11 15:24 , Daniel Fischer wrote: want. You could then also enable OverlappingInstances, which would allow you to write other instances, but that extension is widely regarded as dangerous (have to confess, I forgot what the dangers wer

Re: [Haskell-cafe] Inheritance and Wrappers

2011-01-31 Thread Henning Thielemann
On Mon, 31 Jan 2011, MattMan wrote: I'm new to Haskell, and am trying to implement some simple typeclasses for doing algebra. For example I have type class (simplified for the sake of argument) class AbGroup a where add :: a -> a -> a I would like any type instantiating Num to also be an

Re: [Haskell-cafe] Inheritance and Wrappers

2011-01-31 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 1/31/11 15:24 , Daniel Fischer wrote: > want. You could then also enable OverlappingInstances, which would allow > you to write other instances, but that extension is widely regarded as > dangerous (have to confess, I forgot what the dangers were,

Re: [Haskell-cafe] Inheritance and Wrappers

2011-01-31 Thread Daniel Fischer
On Monday 31 January 2011 20:58:02, MattMan wrote: > tldr: Can I make arbitrary instances of one class instantiate another > without using wrappers? > > I'm new to Haskell, and am trying to implement some simple typeclasses > for doing algebra. For example I have type class (simplified for the > s

Re: [Haskell-cafe] Inheritance and Wrappers

2011-01-31 Thread Steffen Schuldenzucker
On 01/31/2011 08:58 PM, MattMan wrote: [...] data Wrapper a = Wrap a instance (Num a) => AbGroup (Wrapper a) where add (Wrap i) (Wrap j) = Wrap(i+j) However, this is clumsy. Is there something else I can do? Thanks This is the normal approach. You can do funny things with the Overlapp

[Haskell-cafe] Inheritance and Wrappers

2011-01-31 Thread MattMan
tldr: Can I make arbitrary instances of one class instantiate another without using wrappers? I'm new to Haskell, and am trying to implement some simple typeclasses for doing algebra. For example I have type class (simplified for the sake of argument) class AbGroup a where add :: a -> a ->