Re: [Haskell-cafe] Factoring into type classes

2009-01-22 Thread Patai Gergely
Hello again, I think that I have done all of the above in different situations, and so I don't think that there is a single correct answer. I usually avoid using the newtype trick as I find it inconvenient: usually the newtype does not have the same operations as the underlying type and so

Re: [Haskell-cafe] Factoring into type classes

2009-01-20 Thread Conor McBride
Hi folks I have been known to venture the viewpoint that the newtype trick might benefit from improved library support, for example, here http://www.mail-archive.com/haskell-cafe@haskell.org/msg37213.html This is in a similar vein to Derek's approach, if accompanied by a little more

Re: [Haskell-cafe] Factoring into type classes

2009-01-20 Thread Iavor Diatchki
Hello, I don't mean to be negative here but I really fail to see how do any of these ideas help the situation. (I do think it would be cool to have a generic way to lift functions from one type to another that is isomorphic to it). The fundamental problem is that there are multiple functions of

Re: [Haskell-cafe] Factoring into type classes

2009-01-20 Thread wren ng thornton
Luke Palmer wrote: On Mon, Jan 19, 2009 at 3:58 AM, Patai Gergely patai_gerg...@fastmail.fmwrote: However, there are other type classes that are too general to assign such concrete uses to. For instance, if a data structure can have more than one meaningful (and useful) Functor or Monoid

Re: [Haskell-cafe] Factoring into type classes

2009-01-20 Thread wren ng thornton
Patai Gergely wrote: Hi everyone, I have a general program design question, but I can't really think of good examples so it will be a bit vague. There was a discussion on Show not long ago which brought up the problem that there are several ways to show a data structure, and it depends on the

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Eugene Kirpichov
As for multiple Monoid or Functor instances, simply define a newtype, as it is done in Data.Monoid. What part of your question does that answer and what part doesn't it? 2009/1/19 Patai Gergely patai_gerg...@fastmail.fm: Hi everyone, I have a general program design question, but I can't really

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Luke Palmer
On Mon, Jan 19, 2009 at 3:58 AM, Patai Gergely patai_gerg...@fastmail.fmwrote: However, there are other type classes that are too general to assign such concrete uses to. For instance, if a data structure can have more than one meaningful (and useful) Functor or Monoid instance, As a side

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Antoine Latter
2009/1/19 Luke Palmer lrpal...@gmail.com: As a side curiosity, I would love to see an example of any data structure which has more than one Functor instance. Especially those which have more than one useful functor instance. (,) ? -Antoine ___

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Thomas DuBuisson
2009/1/19 Luke Palmer lrpal...@gmail.com: On Mon, Jan 19, 2009 at 3:58 AM, Patai Gergely patai_gerg...@fastmail.fm wrote: However, there are other type classes that are too general to assign such concrete uses to. For instance, if a data structure can have more than one meaningful (and

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Daniel Fischer
Am Montag, 19. Januar 2009 14:31 schrieb Antoine Latter: 2009/1/19 Luke Palmer lrpal...@gmail.com: As a side curiosity, I would love to see an example of any data structure which has more than one Functor instance. Especially those which have more than one useful functor instance. (,) ?

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Holger Siegel
Am Montag, den 19.01.2009, 14:47 +0100 schrieb Daniel Fischer: Am Montag, 19. Januar 2009 14:31 schrieb Antoine Latter: 2009/1/19 Luke Palmer lrpal...@gmail.com: As a side curiosity, I would love to see an example of any data structure which has more than one Functor instance. Especially

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Lennart Augustsson
The desugaring of (, a) would involve some type level lambda, and that's not something that is available (yet). -- Lennart On Mon, Jan 19, 2009 at 1:49 PM, Holger Siegel holgersiege...@yahoo.de wrote: Am Montag, den 19.01.2009, 14:47 +0100 schrieb Daniel Fischer: Am Montag, 19. Januar 2009

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Patai Gergely
As a side curiosity, I would love to see an example of any data structure which has more than one Functor instance. Especially those which have more than one useful functor instance. data Record a b = R { field1 :: a, field2 :: b } If I want to use fmap to transform either field, I have to

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Iavor Diatchki
Hello, The multitude of newtypes in the Monoid module are a good indication that the Monoid class is not a good fit for the class system (it is ironic that discussing it resulted in such a huge thread recently :-). How I'd approach the situation that you describe would depend on the context

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Jonathan Cast
On Mon, 2009-01-19 at 10:59 -0800, Iavor Diatchki wrote: Hello, The multitude of newtypes in the Monoid module are a good indication that the Monoid class is not a good fit for the class system I would say rather that the class system is not a good fit for Monoid. Proposals for local

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Iavor Diatchki
Hi, On Mon, Jan 19, 2009 at 11:06 AM, Jonathan Cast jonathancc...@fastmail.fm wrote: On Mon, 2009-01-19 at 10:59 -0800, Iavor Diatchki wrote: Hello, The multitude of newtypes in the Monoid module are a good indication that the Monoid class is not a good fit for the class system I would say

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Alberto G. Corona
This is one of the shortcomings of haskell not to mention other programming languages. Mathemathicist would find it very annoying. Instead of instance Monoid Integer where mappend = (+) mempty = 0 instance Monoid Integer where mappend = (*) mempty = 1 which is not legal and the

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Jonathan Cast
On Mon, 2009-01-19 at 12:10 -0800, Iavor Diatchki wrote: I usually avoid using the newtype trick as I find it inconvenient: usually the newtype does not have the same operations as the underlying type and so it cannot be used directly, and if you are going to wrap thing just when you

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Derek Elkins
On Mon, 2009-01-19 at 21:18 +0100, Alberto G. Corona wrote: This is one of the shortcomings of haskell not to mention other programming languages. Mathemathicist would find it very annoying. Instead of instance Monoid Integer where mappend = (+) mempty = 0 instance Monoid

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Miguel Mitrofanov
I'd prefer something like Sum :: Monoid Integer Sum = Monoid {mappend = (+), mempty = 0} Prod :: Monoid Integer Prod = Monoid {mappend = (*), mempty = 1} instance Sum in [some code using mempty and mappend] On 19 Jan 2009, at 23:18, Alberto G. Corona wrote: This is one of the shortcomings of

Re: [Haskell-cafe] Factoring into type classes

2009-01-19 Thread Derek Elkins
On Mon, 2009-01-19 at 12:10 -0800, Iavor Diatchki wrote: Hi, On Mon, Jan 19, 2009 at 11:06 AM, Jonathan Cast jonathancc...@fastmail.fm wrote: On Mon, 2009-01-19 at 10:59 -0800, Iavor Diatchki wrote: Hello, The multitude of newtypes in the Monoid module are a good indication that the