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!