# Primitive types and Prelude shenanigans

William Lee Irwin III wli@holomorphy.com
Fri, 16 Feb 2001 01:17:38 -0800

```William Lee Irwin III <wli@holomorphy.com> pisze:
>> 	literal "0" gets mapped to zero :: AdditiveMonoid t => t
>> 	literal "1" gets mapped to one :: MultiplicativeMonoid t => t
>> 	literal "5" gets mapped to (fromPositiveInteger 5)
>> 	literal "-9" gets mapped to (fromNonZeroInteger -9)

On Fri, Feb 16, 2001 at 08:09:58AM +0000, Marcin 'Qrczak' Kowalczyk wrote:
> Actually -9 gets mapped to negate (fromInteger 9). At least in theory,
> because in ghc it's fromInteger (-9) AFAIK.

Sorry I was unclear about this, I had in mind that in the scheme I was
going to implement that the sign of the literal value would be discerned
and negative literals carried to fromNonZeroInteger (-9) etc.

William Lee Irwin III <wli@holomorphy.com> pisze:
>> The motivation behind this is so that some fairly typical
>> mathematical objects (multiplicative monoid of nonzero integers,
>> etc.) can be directly represented by numerical literals (and
>> primitive types).

On Fri, Feb 16, 2001 at 08:09:58AM +0000, Marcin 'Qrczak' Kowalczyk wrote:
> I am definitely against it, especially the zero and one case.
> When one can write 1, he should be able to write 2 too obtaining the
> same type. It's not hard to write zero and one.

The real hope here is to get the distinct zero and one for things that
are already traditionally written that way, like the multiplicative
monoid of nonzero integers or the additive monoid of natural numbers.
Another implication I view as beneficial is that the 0 (and 1) symbols
can be used in vector (and perhaps matrix) contexts without the
possibility that other integer literals might be used inadvertantly.

On Fri, Feb 16, 2001 at 08:09:58AM +0000, Marcin 'Qrczak' Kowalczyk wrote:
> What next: 0 for nullPtr and []?

It's probably good to point out that this scheme is "permissive" enough,
or more specifically, allows enough fine-grained expressiveness to allow
the symbol to be overloaded for address types on which arithmetic is
permitted, and lists under their natural monoid structure, which I agree
is aesthetically displeasing at the very least, and probably undesirable
to allow by default.

On Fri, Feb 16, 2001 at 08:09:58AM +0000, Marcin 'Qrczak' Kowalczyk wrote:
> Moreover, the situation where each integer literal means applied
> fromInteger is simple to understand, remember and use. I don't want to
> define a bunch of operations for the same thing. Please keep Prelude's
> rules simple.

I don't think this sort of scheme is appropriate for a standard Prelude
either, though I do think it's interesting to me, and perhaps others. I
don't mean to give the impression that I'm proposing this for inclusion
in any sort of standard Prelude. It's a more radical point in the design
space that I am personally interested in exploring both to discover its
implications for programming (what's really awkward, what things become
convenient, etc.), and to acquaint myself with the aspects of the
compiler pertinent to the handling of primitive types.

Cheers,
Bill

```