Hasty Briefsbeta

Bilingual

Type-checked non-empty strings

a month ago
  • The article describes a Haskell technique for creating type-checked non-empty strings using RequiredTypeArguments from GHC 9.10.
  • It presents a type-level validation mechanism that replaces TemplateHaskell calls, leading to a ~10% build-time improvement in a data-heavy package.
  • The technique uses a type family or typeclass to enforce non-empty strings at compile time, with custom error messages for invalid inputs.
  • Examples include implementing a NonEmptyText type and extending the approach to validate DynamoDB table names with regex-like constraints.
  • The article notes limitations, such as GHC's reduction limit and complexity in expressing non-trivial algorithms at the type level.
  • It concludes by discussing the trend towards Dependent Haskell and acknowledges potential risks with UndecidableInstances.