Is it possible to “extend” the F# compiler to do custom compile-time string checks? I’m thinking of something similar to the checks on StringFormat strings when using sprintf etc. When I say “extend”, I don’t mean build a custom version of the compiler, I mean use existing supported techniques.
Off the top of my head, you might have a RegexFormat type. You provide the regex and the compiler would do the static analysis using the regex. E.g.
//Setup RegexFormat with IP address regex and type abbreviation IpRegexFormat?
//Compile error. ipAddress expects IpRegexFormat!
let ip = ipAddress "192.168.banana.1"
If not, maybe this is a type provider for me 🙂 – If the whole thing is a terrible idea, let me know!
We have a Regex type provider in Fsharpx.
Here are some samples:
It’s not exactly what you are looking for, but I guess you could easily take this type provider and customize it with your static literal rules.