Re: [Haskell-cafe] Idiomatic ways to make all instances of a certain class also instances of another?

2011-07-27 Thread Alexander Solla
On Tue, Jul 26, 2011 at 11:58 PM, Tim Cowlishaw wrote: > On Tue, Jul 26, 2011 at 11:14 PM, Alexander Solla > wrote: > > > data OrderType = Market Size | Limit LimitPrice Expiration Size | Stop > > (Either Percent Price) > > newtype Sell = Sell OrderType > > newtype Buy = Buy OrderType > > newtype

Re: [Haskell-cafe] Idiomatic ways to make all instances of a certain class also instances of another?

2011-07-26 Thread Tim Cowlishaw
On Tue, Jul 26, 2011 at 11:14 PM, Alexander Solla wrote: > data OrderType = Market Size | Limit LimitPrice Expiration Size | Stop > (Either Percent Price) > newtype Sell = Sell OrderType > newtype Buy = Buy OrderType > newtype Order = Order (Either Buy Sell) > size :: Order -> Int > size (Order

Re: [Haskell-cafe] Idiomatic ways to make all instances of a certain class also instances of another?

2011-07-26 Thread Henning Thielemann
On Tue, 26 Jul 2011, Tim Cowlishaw wrote: For instance, for a typeclass representing the interface that any Order type should implement: class Order o where price :: o -> Int size :: o -> Int I'd like to be able to specify an Eq instance for all types of class Order in a manner similar to t

Re: [Haskell-cafe] Idiomatic ways to make all instances of a certain class also instances of another?

2011-07-26 Thread Alexander Solla
On Tue, Jul 26, 2011 at 1:52 PM, Tim Cowlishaw wrote: > On Tue, Jul 26, 2011 at 7:46 PM, Evan Laforge wrote: > > > Could you give a specific example of the problem you're trying to solve? > > Sorry, yes, that'd be useful :-) > > So, the project I'm working on involves developing a simulation of a

Re: [Haskell-cafe] Idiomatic ways to make all instances of a certain class also instances of another?

2011-07-26 Thread Tim Cowlishaw
On Tue, Jul 26, 2011 at 7:46 PM, Evan Laforge wrote: > Could you give a specific example of the problem you're trying to solve? Sorry, yes, that'd be useful :-) So, the project I'm working on involves developing a simulation of a securities market. I have a type which models an order book, on w

Re: [Haskell-cafe] Idiomatic ways to make all instances of a certain class also instances of another?

2011-07-26 Thread Evan Laforge
> However, I'd be curious to know if (a) There are better or more > idiomatic ways of achieving the same effect, and (b) Whether or not I > should be doing this at all; It did occur to me that this seems rather > trying to re-implement OOP-style inheritance with typeclasses, and > therefore perhaps

Re: [Haskell-cafe] Idiomatic ways to make all instances of a certain class also instances of another?

2011-07-26 Thread Stephen Tetley
For: instance (Ord a) => Max a where maximum = max The same could more simply be achieved with a function: maximum :: Ord a => a maximum = max Now, you probably wanted both a base-case using max and type specific, special cases: instance Max Int where maximum = 2^16 If you have both instan

[Haskell-cafe] Idiomatic ways to make all instances of a certain class also instances of another?

2011-07-26 Thread Tim Cowlishaw
Hi all, I'm currently embarking on my first major project in Haskell, after dabbling with it for several years, and seem to keep finding myself in situations where I create a typeclass that seems to be some sort of specialisation of another, more general typeclass. Given that this is the case, I'v