Add IsNumeric (similar to IsString and IsList)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Add IsNumeric (similar to IsString and IsList)

Mikhail Baykov
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.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Add IsNumeric (similar to IsString and IsList)

Ivan Lazar Miljenovic
On 12 June 2015 at 17:04, Michael Baikov <[hidden email]> 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.

Is this strictly to replace/augment fromInteger or are you proposing
one for fromRational as well?

--
Ivan Lazar Miljenovic
[hidden email]
http://IvanMiljenovic.wordpress.com
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Add IsNumeric (similar to IsString and IsList)

Mikhail Baykov
I guess we can have something similar for rationals as well, I haven't
considered those.

On Mon, Jun 15, 2015 at 12:41 PM, Ivan Lazar Miljenovic
<[hidden email]> wrote:

> On 12 June 2015 at 17:04, Michael Baikov <[hidden email]> 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.
>
> Is this strictly to replace/augment fromInteger or are you proposing
> one for fromRational as well?
>
> --
> Ivan Lazar Miljenovic
> [hidden email]
> http://IvanMiljenovic.wordpress.com
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Add IsNumeric (similar to IsString and IsList)

Ivan Lazar Miljenovic
On 15 June 2015 at 14:56, Michael Baikov <[hidden email]> wrote:
> I guess we can have something similar for rationals as well, I haven't
> considered those.

I wouldn't call it IsNumeric then, as to me it implies it could be *any* number.

IsIntegral maybe though.

But I too would like something like this, whatever the name.

>
> On Mon, Jun 15, 2015 at 12:41 PM, Ivan Lazar Miljenovic
> <[hidden email]> wrote:
>> On 12 June 2015 at 17:04, Michael Baikov <[hidden email]> 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.
>>
>> Is this strictly to replace/augment fromInteger or are you proposing
>> one for fromRational as well?
>>
>> --
>> Ivan Lazar Miljenovic
>> [hidden email]
>> http://IvanMiljenovic.wordpress.com



--
Ivan Lazar Miljenovic
[hidden email]
http://IvanMiljenovic.wordpress.com
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Add IsNumeric (similar to IsString and IsList)

Carter Schonwald
In reply to this post by Mikhail Baykov
have you tried  using rebindable syntax + noImplicitPrelude?  That *should* allow you to model this by just having a distinguished fromInteger function in scope during desugaring/type checking. 
At the very least, its worth experimenting with.



On Mon, Jun 15, 2015 at 12:56 AM, Michael Baikov <[hidden email]> wrote:
I guess we can have something similar for rationals as well, I haven't
considered those.

On Mon, Jun 15, 2015 at 12:41 PM, Ivan Lazar Miljenovic
<[hidden email]> wrote:
> On 12 June 2015 at 17:04, Michael Baikov <[hidden email]> 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.
>
> Is this strictly to replace/augment fromInteger or are you proposing
> one for fromRational as well?
>
> --
> Ivan Lazar Miljenovic
> [hidden email]
> http://IvanMiljenovic.wordpress.com
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Add IsNumeric (similar to IsString and IsList)

Marcin Mrotek
+1. Moving cruft out of Num seems like a noble goal to me.

Best regards,
Marcin Mrotek
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Add IsNumeric (similar to IsString and IsList)

Chris Wong-2
In reply to this post by Mikhail Baykov
On Fri, Jun 12, 2015 at 7:04 PM, Michael Baikov <[hidden email]> 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.

I don't otherwise have an opinion.

--
https://lambda.xyz
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Add IsNumeric (similar to IsString and IsList)

Ivan Lazar Miljenovic
On 15 June 2015 at 18:05, Chris Wong <[hidden email]> wrote:

> On Fri, Jun 12, 2015 at 7:04 PM, Michael Baikov <[hidden email]> 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
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe



--
Ivan Lazar Miljenovic
[hidden email]
http://IvanMiljenovic.wordpress.com
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Add IsNumeric (similar to IsString and IsList)

Ben Franksen
Ivan Lazar Miljenovic wrote:

> On 15 June 2015 at 18:05, Chris Wong <[hidden email]> wrote:
>> On Fri, Jun 12, 2015 at 7:04 PM, Michael Baikov <[hidden email]>
>> wrote:
>>> 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.

Can anyone explain to me why IsString was named so and not FromString? I
wonder about that every time I encounter this class. Would it not make more
sense to break with this rather unfortunate naming convention?

Cheers
Ben
--
"Make it so they have to reboot after every typo." ― Scott Adams


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe