core lib attempt#2: problem with hard-wired module namesforclasses in GHC

Simon Peyton-Jones simonpj at
Thu Oct 5 11:06:48 EDT 2006

| using types and classes that are in scope, of course. i have several
| more examples but because it's not required for me nor important for
| you, i will put them all into a ticket. ok?


| what is the simplest way to experiment with my own version of base
| library? can it be accomplished without recompiling entire GHC?

Check out
and please add to it as you learn more.

If you want to change which wired-in or known-key things live in which
module then you have to change PrelNames, and recompile GHC.  Not a big
job; you only change one module.

If you are not changing which module things live in, then you don't need
to recompile GHC.

| guess, that i'm trying to do? ;)  is it possible to define, say, Enum
| class in module Core.Base and then import this module in GHC.Enum?
| this will make circular dependency - usage of Enum instances in
| Core.Base will be resolved via definition in GHC.Enum while this
| will import for definition Core.Base. but this scheme will allow
| compatibility with existing GHC versions that is a big plus. so can it
| work?

Trying to keep "compatibility with existing GHC versions" is a very
strong restriction.  Making recursive loops in GHC/* modules is likely
to be bad.  I advise against it.

| there are several definition that use c@(C# _), like this:
|     jhead n cs
|         | n < 10    = case unsafeChr (ord '0' + n) of
|             c@(C# _) -> c : cs
|         | otherwise = case unsafeChr (ord '0' + r) of
|             c@(C# _) -> jhead q (c : cs)
|         where
|         (q, r) = n `quotRemInt` 10
| i guess that it is for strictness and can be replaced with calls to
|             c -> c `seq` c : cs

I think so, yes.  Provided seq is in scope.

| There a few of Float/Double-related RULES in GHC.Base:
| {-# RULES
| "plusFloat x 0.0"   forall x#. plusFloat#  x#   0.0# = x#
| ....

If the RULE was in a random module M, GHC would need to be sure to read
M.hi just in case the rule was useful.  If you move this RULE to
GHC.Float, say, then GHC will have to read GHC.Float on every
compilation, just in case you call 'plusFloat#'.  But GHC.Base is read
every compilation anyway, so it seems the best place to put it.


More information about the Glasgow-haskell-users mailing list