[Haskell-cafe] Num instances for 2-dimensional types

Daniel Fischer daniel.is.fischer at web.de
Mon Oct 5 11:02:19 EDT 2009


Am Montag 05 Oktober 2009 16:29:02 schrieb Job Vranish:
> In what way is it not a number?
>

If there's a natural[1] implementation of fromInteger, good.
If there isn't, *don't provide one*. 
fromInteger _ = error "Not sensible" is better than doing something strange.

[1] In the case of residue class rings, you may choose between restricting the range of 
legitimate arguments for fromInteger or doing a modulo operation on the argument, both 
ways are natural and meet expectations sufficiently well.


>
> Sönke Hahn:
>   btw, I forgot to mention in my first email, but
>       fromInteger n = (r, r) where r = fromInteger n
>   is better than:
>       fromInteger n = (fromInteger n, 0)
>  as you get a lot of corner cases otherwise.
>
>  I use fromInteger = pure . fromInteger, which when combined with my
> Applicative instance, is effectively the same as your:  fromInteger n = (r,
> r) where r = fromInteger n
>
>
> - Job
>
> On Mon, Oct 5, 2009 at 9:12 AM, Miguel Mitrofanov <miguelimo38 at yandex.ru>wrote:
> > Sönke Hahn wrote:
> >
> >  I used to implement
> >
> >>    fromInteger n = (r, r) where r = fromInteger n
> >>
> >> , but thinking about it,
> >>    fromInteger n = (fromInteger n, 0)
> >>
> >> seems very reasonable, too.
> >
> > Stop pretending something is a number when it's not.




More information about the Haskell-Cafe mailing list