Primitive types and Prelude shenanigans

William Lee Irwin III wli@holomorphy.com
Mon, 12 Feb 2001 14:38:25 -0800


On Mon, Feb 12, 2001 at 11:00:02AM +0100, Marcin 'Qrczak' Kowalczyk wrote:
> It depends on the implementation and IMHO it would be bad to require
> a particular implementation for no reason. For example ghc uses the gmp
> library and does not implement Integers in terms of Naturals; gmp handles
> negative numbers natively.

I'm aware natural numbers are not a primitive data type within Haskell;
I had the idea in mind that for my own experimentation I might add them.

On Mon, Feb 12, 2001 at 11:00:02AM +0100, Marcin 'Qrczak' Kowalczyk wrote:
> You can define it yourself by wrapping not-necessarily-positive types
> if you feel the need. Most of the time there is no need because Haskell
> has no subtyping - they would be awkward to use together with present
> types which include negative numbers.

Perhaps I should clarify my intentions:
The various symbols for integer literals all uniformly denote the values
fromInteger #n where #n is some monotype or other. What I had in mind
was (again, for my own wicked purposes) treating specially the symbols
0 and 1 so that the implicit coercions going on are for the type
classes where additive and multiplicative identities exist, then
overloading the positive symbols so that the implicit coercion is
instead fromNatural, and then leaving the negative symbols (largely) as
they are.

This is obviously too radical for me to propose it as anything, I intend
to only do it as an experiment or perhaps for my own usage (though if
others find it useful, they can have it).

On Mon, Feb 12, 2001 at 11:00:02AM +0100, Marcin 'Qrczak' Kowalczyk wrote:
> Modules with names beginning with Prel define approximately everything
> what Prelude includes and everything with magic support in the compiler.

I've not only already found these, but in attempting to substantially
alter them I've run into the trouble below:

On Mon, Feb 12, 2001 at 11:00:02AM +0100, Marcin 'Qrczak' Kowalczyk wrote:
> PrelGHC defines primops that are hardwired in the compiler, and PrelBase
> is a basic module from which most things begin. In particular Bool is
> defined there as a regular algebraic type
>     data Bool = False | True

The magic part I don't seem to get is that moving the definition of Bool
around and also changing the types of various things assumed to be Bool
causes things to break. The question seems to be of figuring out what
depends on it being where and how to either make it more flexible or
accommodate it.

On Mon, Feb 12, 2001 at 11:00:02AM +0100, Marcin 'Qrczak' Kowalczyk wrote:
[useful info not needing a response snipped]

On Mon, 12 Feb 2001, William Lee Irwin III wrote:
>> I'd also like to see where some of the magic behind the typing of
>> various other built-in constructs happens, like list comprehensions,
>> tuples, and derived classes.

On Mon, Feb 12, 2001 at 11:00:02AM +0100, Marcin 'Qrczak' Kowalczyk wrote:
> Inside the compiler, not in libraries.

I had in mind looking within the compiler, actually. Where in the
compiler? It's a big program, it might take me a while to do an
uninformed search. I've peeked around a little bit and not gotten
anywhere.


Cheers,
Bill