[Haskell-cafe] Type checking string literal in Haskell?

Niklas Haas haskell at nand.wakku.to
Sat Mar 1 12:45:15 UTC 2014

On Sat, 1 Mar 2014 21:35:09 +0900, KwangYul Seo <kwangyul.seo at gmail.com> wrote:
> In Java, the Checker Framework (
> http://types.cs.washington.edu/checker-framework/) provides a way to type
> check string literals. For example, Java signatures type system
> differentiates strings literals in different forms:
> 1. Unqualified strings :
> "Hello, world!" -> @Unqualified String
> 2. Fully qualified names:
> "package.Outer.Inner" -> @FullyQualifiedString String
> 3. Binary names:
> "package.Outer$Inner" -> @BinaryName String
> 4. Field descriptors:
> "Lpackage/Outer$Inner;" -> @FieldDescriptor String
> It can do the similar checks with regular expressions or SQL statements.
> Is it possible to type check string literals in Haskell? I think it would
> be nice if we can check if a given string literal is a valid URL or an
> email address at compile time.
> Regards,
> Kwang Yul Seo
Non-text part: text/html
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

I think QuasiQuoters were designed for pretty much this purpose. They're
basically functions from Strings to expressions (or
types/declarations/patterns, depending on the context).

A quasiquoter like [url|http://example.com] could parse the string
passed to it ("http://example.com") at compile time and return an
expression of type URL (or throw an error or something else), or maybe
even some other data structure that will end up being useful.

More information about the Haskell-Cafe mailing list