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 6090171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:11:01+00:00 2026-05-23T12:11:01+00:00

I’m working on IronJS, and one of our source files is getting very long.

  • 0

I’m working on IronJS, and one of our source files is getting very long.

Right now, I’m trying to get .NET interop working. I’m adding the TryBinaryOperation method to the Undefined so that C# can use the JavaScript semantics of the Undefined value.

However, this introduces a dependency on the Operators type, which causes a circular dependency.

Runtime.fs:

type BoxedValue() =
    struct
        // Contains IsUndefined and get_Undefined, referencing the Undefined class, below.

...

and type Undefined() =
    inherit DynamicObject()
    ...
    override x.TryBinaryOperation(binder:BinaryOperationBinder, arg:obj, result:obj byref) : bool =
        // Here, we are referencing BoxedValue, above.
        result <- Operators.add(Und, BoxedValue.Box(arg))
        true

...

Operators.fs:

type Operators =
    ...
    // Here, we are referencing BoxedValue.
    static member add(BoxedValue l, BoxedValue r)
        ...

So, we have this set of dependencies:
BoxedValue->Undefined, Undefined->BoxedValue, Undefined->Operators, Operators->BoxedValue

Ideally, we would like to split each of these into its own file.

Is it possible in F# to have cross-file circular dependencies?

  • 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-23T12:11:01+00:00Added an answer on May 23, 2026 at 12:11 pm

    There is no direct way to write circular dependencies between types defined in separate files (in the current version of F#). In general, the way to solve the problem is to break one of the dependencies and allow some form of parameterization. Then you can fill the hole to build the circular reference later.

    In your example, you can probably reasonably easily parameterize the Undefined type to take the reference to Operators as a parameter. If you need more functions, then you can use an interface. For just a single function (like Operators.add) you can write something like this:

    and type Undefined() =
        inherit DynamicObject()
        ...
        // To be specified by code defined later 
        // (this can either be a function or an interface implementation)
        static let mutable addition = (fun x y -> failwith "not initialized")
        static member SetAddition(f) = addition <- f
    
        override x.TryBinaryOperation
                (binder:BinaryOperationBinder, arg:obj, result:obj byref) : bool =
            // Here, we are referencing BoxedValue, above.
            result <- addition(Und, BoxedValue.Box(arg))
            true
    

    The code in Operators.fs would provide the implementation:

    type Operators =
        ...
        // Static constructor of the `Operators` type
        static do Undefined.SetAddition(Operators.add)
        ....
    
        // Here, we are referencing BoxedValue.
        static member add(BoxedValue l, BoxedValue r)
    

    The only tricky thing is that you need to make sure that the static constructor of Operators will get called before the Undefined type is used for the first time. This depends on your specific case, but there is usually some way to do that. (There is probably some main type that can run the initialization)

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to select an H1 element which is the second-child in its group
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.