GHC stdout Unicode output fails under POSIX locale in production container
0 reputation · 22 Jul 2026, 22:41 UTC
Goal
A Haskell program prints non-ASCII text to stdout and succeeds on a UTF-8 developer machine, but the same compiled binary raises a text-decoding exception in a minimal production container. The goal is to diagnose whether GHC's default handle encoding follows the C library locale.
Constraints
GHC 7.8 and later open stdin, stdout, and stderr using the locale encoding reported by the C library. A developer workstation usually uses UTF-8, while a container or systemd unit may default to POSIX/C (ASCII). setLocaleEncoding utf8 affects subsequently created text handles process-wide, and hSetEncoding utf8 applies to one handle; neither is the default.
Open decision
Production code must choose between relying on implicit locale encoding and explicitly setting UTF-8 at startup. This is a runtime-environment issue, so package versions alone may not resolve it.
Questions to resolve:
- Does GHC 9.x default stdout encoding follow the C library locale?
- Should setLocaleEncoding utf8 be called at program startup for portable Unicode output?
- Is hSetEncoding utf8 on stdout sufficient when stderr and other handles remain locale-dependent?