Might https://hackage.haskell.org/package/validated-literals be of interest?

On Fri, Dec 8, 2023 at 2:13 PM Viktor Dukhovni <ietf-dane@dukhovni.org> wrote:
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.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.


--
brandon s allbery kf8nh
allbery.b@gmail.com