At first, I wanted to look into how Integer was deriving from the classOrd
I got that definition in GHC.Classes
instance Ord Integer where
(<=) = leInteger
(>) = gtInteger
(<) = ltInteger
(>=) = geInteger
compare = compareInteger
compareInteger is pointing to another source file, GHC.Integer.Type. it is defined like this :
compareInteger :: Integer -> Integer -> Ordering
compareInteger (Jn# x) (Jn# y) = compareBigNat y x
compareInteger (S# x) (S# y) = compareInt# x y
compareInteger (Jp# x) (Jp# y) = compareBigNat x y
compareInteger (Jn# _) _ = LT
compareInteger (S# _) (Jp# _) = LT
compareInteger (S# _) (Jn# _) = GT
compareInteger (Jp# _) _ = GT
S# is for fixed-size integers, Jn# and Jp# for arbitrary size integers.
In GHC.Classes (from the package ghc-prim) I was able to find a definition for compareInt#. The occurence of unusual types like Int# signaled me I was getting closer.
compareInt# :: Int# -> Int# -> Ordering
compareInt# x# y#
| isTrue# (x# <# y#) = LT
| isTrue# (x# ==# y#) = EQ
| True = GT
Still going deeper, I got this definition for the operator (GHC.Prim module)
infix 4 <#
(<#) :: Int# -> Int# -> Int#
(<#) = (<#)
But this is a deep I was able to get. <# is refering to itself. We don’t know what it’s doing.
(isTrue# is simply a function that “Returns True if its parameter is 1# and False if 0#”)
Where can I find the source, the actual place where the job is getting done ? Is there some assembly at the very bottom ? Where do I find this sacred place ?