Re: [Haskell-cafe] Thoughts about redesigning "Num" type class

I sencond the statement that semirings might be a useful typeclass to have. Another example: Non-negative reals with infinity, the values that a measure can take. Nevertheless the biggest issue is what _symbol_ to use for the operations. We know that a ring is a semigroup in two ways, and no matter what semigroup structure we think the ring to "originate" from, we're going to annoy the other half of users who thought it the other way around. Some semigroups are thought of as (+), others as (*). Picking one of these symbols for all semigroups will be counter-intuitive for some structures. As to affine structures, Martin Escardo and Alex Simpson have a paper showing that the unit interval is the free cancellative midpoint algebra over two generators. They have Haskell code for this [1]. And yes, a typeclass is not a mathematical category, but Haskell is a language that lets you formalise quite a bit of category theory, and this is a cool thing to have. You can read a paper based on category theory and obtain executable code with very little effort. There are now entire Ph.D. theses written in Agda. To me it seems that the solution to the Num typeclass problem would be to have sub-typeclass statements that let you introduce aliases for the operations, as so: class Semigroup a where (<>) :: a -> a -> a class Group a where (*) :: a -> a -> a unit :: a inverse :: a -> a superclass Semigroup Group where (<>) = (*) But wait, we do have a mechanism for aliases: It's called newtype! Conclusion: If you want to express that any Num instance is a Group, do so with a newtype. Data.Monoid is a good example for this. -- Olaf [1] http://www.cs.bham.ac.uk/~mhe/.talks/map2011/martin_map.pdf

Le 12/09/2015 14:39, Olaf Klinke a écrit :
semirings might be a useful typeclass to have. Another example: Non-negative reals with infinity, the values that a measure can take. Could you mention, please, a system whose measures are for sure positive reals, infinity included? Perhaps your definition of "measure"should be precised... Thanks.
Jerzy Karczmarczuk

I have this deep worry that any changes to num hierarchy that aren't first demonstrated in userland. This is perhaps me being a little bit of a curmudgeon. I just feel like it's a complicated topic that needs lots of concrete example experiments to really pin down what's what. Additionally, most of the proposals over time seem to a) have some latent form of abstraction blindness with respect to some notion of parametrization that we can't even name / describe with Haskell (Which is actually something I'm starting to think about, though often passing around records of functions is good enough, ignoring the question of performance implications) B) there's usually a whole bunch of different computable realizations of how to Manipulate a given mathematical object, which when exposed as apis hsve wildly different performance characteristics and ease of use An example of (a) is we can't really talk about a family of type classes which are parametrized over the names of their methods. (We spend so much time jumping through that hoop when relating ring and group structures! An example of the latter (b) would be any model of integration / measurable functions. We as humans are still learning on that front. Witness the huge amount of work (still nascent) in probabilistic programming, which is essentially about "what is an efficient and usable way to talk about integrating over interesting things" On Saturday, September 12, 2015, Jerzy Karczmarczuk < jerzy.karczmarczuk@unicaen.fr> wrote:
Le 12/09/2015 14:39, Olaf Klinke a écrit :
semirings might be a useful typeclass to have. Another example: Non-negative reals with infinity, the values that a measure can take.
Could you mention, please, a system whose measures are for sure positive reals, infinity included? Perhaps your definition of "measure"should be precised... Thanks.
Jerzy Karczmarczuk
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

On 12/09/2015 at 14:39:53 +0200, Olaf Klinke wrote:
I sencond the statement that semirings might be a useful typeclass to have. Another example: Non-negative reals with infinity, the values that a measure can take. Nevertheless the biggest issue is what _symbol_ to use for the operations. We know that a ring is a semigroup in two ways, and no matter what semigroup structure we think the ring to "originate" from, we're going to annoy the other half of users who thought it the other way around. Some semigroups are thought of as (+), others as (*). Picking one of these symbols for all semigroups will be counter-intuitive for some structures.
Consider this: class Semigroup a where (<>) :: a -> a -> a newtype Sum a = Sum a newtype Product a = Product a (+) :: Semigroup (Sum a) => a -> a -> a (*) :: Semigroup (Product a) => a -> a -> a class Semigroup a => Abelian a -- with ConstraintKinds type Semiring a = (Abelian (Sum a), Semigroup (Product a))
participants (4)
-
Carter Schonwald
-
Jerzy Karczmarczuk
-
M Farkas-Dyck
-
Olaf Klinke