
On 15 June 2015 at 18:05, Chris Wong
On Fri, Jun 12, 2015 at 7:04 PM, Michael Baikov
wrote: Hi Cafe!
Now that we have OverloadedList and OverloadedStrings extensions it might make sense to add something similar for numerals - right now if you want to be able to specify some items as numbers you have to implement Num instance, unfortunately not everything that can be represented as number can have sensible operations required by Num: negation makes no sense for set of natural numbers for example, multiplication for some applications of currency values which results in Num instance full of (*) = error "No multipication for Foos", (+) = error "No addition for Foos".
I don't have any statistics from hackage or github, but in codebase I'm working with there are 3 such instances.
Proposal: add OverloadedNumerals language pragma, IsNumeric typeclass and some methods to make that class useful with behavior similar to Lists and Strings.
As for naming: it should be named IsInteger/fromInteger by analogy with IsString/fromString and IsList/fromList.
The problem with calling it "fromInteger" is that it would clobber the existing fromInteger method in the Num class (thus hiding tricks/qualification would be needed when defining/using instances) unless it is split out of Num, but that will probably be more of an uphill battle.
I don't otherwise have an opinion.
-- https://lambda.xyz _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com