Actual Implementation of so called "List" data type

I’m trying to find the actual Implementation of so called “List” data type in the GHC.

What I found are the following two places.

  1. https://hackage.haskell.org/package/ghc-prim-0.9.0/docs/src/GHC.Types.html

Here you can find it by searching (Ctrl + F) for data [] a = [] | a : [a].

Nearby the above code line, it says that “NB: lists are built-in syntax, and hence not explicitly exported”, which seems to suggests that the actual implementation is implemented somewhere else where built-in syntaxes are implemented, but I could not find it.

  1. https://hackage.haskell.org/package/base-4.18.0.0/docs/src/GHC.Base.html

Here you can find it by searching (Ctrl + F) for data [] a = MkNil.

Nearby the above code line, it says that “-- for use when compiling GHC.Base itself doesn’t work”, which seems to suggest that this also is not the actual implementation.

Where can I find the original actual source code implementation of List?

2 Likes

Lists are part of the class of “wired-in” things, which are definitions that ultimately come from GHC’s internal representation rather than in normal Haskell source files. There’s more about wired-in things on the GHC wiki (wired in · Wiki · Glasgow Haskell Compiler / GHC · GitLab) and the key definitions live in GHC.Builtin.Types (compiler/GHC/Builtin/Types.hs · master · Glasgow Haskell Compiler / GHC · GitLab).

4 Likes