Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8932871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:24:21+00:00 2026-06-15T09:24:21+00:00

Is it possible to extend the F# compiler to do custom compile-time string checks?

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:24:22+00:00Added an answer on June 15, 2026 at 9:24 am

    We have a Regex type provider in Fsharpx.

    Here are some samples:

    type PhoneRegex = Regex< @"(?<AreaCode>^\d{3})-(?<PhoneNumber>\d{3}-\d{4}$)">
    
    [<Test>] 
    let ``Can call typed IsMatch function``() =      
        PhoneRegex.IsMatch "425-123-2345"
        |> should equal true
    
    [<Test>] 
    let ``Can call typed CompleteMatch function``() =      
        PhoneRegex().Match("425-123-2345").CompleteMatch.Value
        |> should equal "425-123-2345"
    
    [<Test>] 
    let ``Can return AreaCode in simple phone number``() =
        PhoneRegex().Match("425-123-2345").AreaCode.Value
        |> should equal "425"
    
    [<Test>] 
    let ``Can return PhoneNumber property in simple phone number``() =
        PhoneRegex().Match("425-123-2345").PhoneNumber.Value
        |> should equal "123-2345"
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to extend user's session expiration time in CI. What I want
Would be possible to extend this kind of layout so that I can have
Is it possible to extend a base template with another template in Smarty? I
Is it possible to extend multiple classes in Scala. For example if I have
Is it possible to extend the rich-text editor to add and other HTML5 elements?
Is it possible to extend dynamically javascript function scope? I tried without success the
Clojure structs can be arbitrarily extended, adding new fields. Is it possible to extend
Is it possible in C# (and I think it's not) to extend int to
In C#, is it possible to extend a class that has no constructors? Maybe
Using ef4 code first you can create and compile classes and dbcontext. What happens

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.