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

  • SEARCH
  • Home
  • 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 821727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:41:15+00:00 2026-05-15T02:41:15+00:00

For recursion in F#, existing documentation is clear about how to do it in

  • 0

For recursion in F#, existing documentation is clear about how to do it in the special case where it’s just one function calling itself, or a group of physically adjacent functions calling each other.

But in the general case where a group of functions in different modules need to call each other, how do you do it?

  • 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-05-15T02:41:16+00:00Added an answer on May 15, 2026 at 2:41 am

    I don’t think there is a way to achieve this in F#. It is usually possible to structure the application in a way that doesn’t require this, so perhaps if you described your scenario, you may get some useful comments.

    Anyway, there are various ways to workaround the issue – you can declare a record or an interface to hold the functions that you need to export from the module. Interfaces allow you to export polymorphic functions too, so they are probably a better choice:

    // Before the declaration of modules
    type Module1Funcs = 
      abstract Foo : int -> int
    type Module2Funcs = 
      abstract Bar : int -> int 
    

    The modules can then export a value that implements one of the interfaces and functions that require the other module can take it as an argument (or you can store it in a mutable value).

    module Module1 = 
      // Import functions from Module2 (needs to be initialized before using!)
      let mutable module2 = Unchecked.defaultof<Module2Funcs>
    
      // Sample function that references Module2
      let foo a = module2.Bar(a)
    
      // Export functions of the module
      let impl = 
        { new Module1Funcs with 
            member x.Foo(a) = foo a }
    
    // Somewhere in the main function
    Module1.module2 <- Module2.impl
    Module2.module1 <- Module1.impl
    

    The initializationcould be also done automatically using Reflection, but that’s a bit ugly, however if you really need it frequently, I could imagine developing some reusable library for this.

    In many cases, this feels a bit ugly and restructuring the application to avoid recursive references is a better approach (in fact, I find recursive references between classes in object-oriented programming often quite confusing). However, if you really need something like this, then exporting functions using interfaces/records is probably the only option.

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

Sidebar

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.