Skip to content

`CmpSymbol` treats "\0" as bigger than expected

Summary

Compared to behaviour of e.g. Ord String or Ord ByteString, CmpSymbol treats string "\0" as bigger than e.g. "a", even though null character appears as first in ASCII ordering.

Steps to reproduce

$ ghci
GHCi, version 8.10.1: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/matej/.ghci
λ> import GHC.TypeLits
λ> :set -XDataKinds
λ> :k! CmpSymbol "a" "\0"
CmpSymbol "a" "\0" :: Ordering
= 'LT
λ> compare "a" "\0"
GT

Same with CmpSymbol "a" "\NUL".

Expected behavior

I expected CmpSymbol "a" "\0" to return 'GT, which is what is returned with characters immediately following \0 in ASCII.

Environment

  • GHC version used: 8.10.1

Optional:

  • Operating System: Arch Linux
  • System Architecture: x64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information