[Haskell-cafe] OverloadedStrings, but with compile-time invariants

Viktor Dukhovni ietf-dane at dukhovni.org
Fri Dec 8 19:12:46 UTC 2023


On Fri, Dec 08, 2023 at 04:50:58PM +0100, Max Ulidtko wrote:

> And overall, to zoom out of "XY Problem" pitfalls: am I missing a neater way
> to have "partial" IsString instances, those that can reject some literals at
> compile-time?
> 
> Having this code work is the goal:
> 
> text1, text2 :: NonEmptyText
> text1 = "hello, types"
> text2 = "" -- compile error

Is at TH splice too cumbersome? 

    text1, text2 :: NonEmptyText
    text1 = $$(neTxt "hello, types")
    text = $$(neTxt "") -- compile error

I am validating DNS domain name literals at compile time, where checks
include full DNS syntax validation with no empty labels, no labels
longer than 63 bytes, and overall wire length at most 255 bytes.

    https://github.com/dnsbase/dnsbase/blob/548270f2e575949592ca3f1e40c58edc450bd0c3/internal/Net/DNSBase/Internal/Domain.hs#L249-L267

-- 
    Viktor.


More information about the Haskell-Cafe mailing list