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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:12:27+00:00 2026-05-29T19:12:27+00:00

I am building two libraries in OCaml which contain the same variant type. The

  • 0

I am building two libraries in OCaml which contain the same variant type. The detail of the variant is not too important, other than that it is really large, and it would be annoying to manually write conversion functions for it. (It’s actually the bfd_architecture enumeration converted from C using ocamlidl).

I’m now writing a program using the two libraries. In particular, I’m calling A.f which returns a value of A.variant_type, and I need to use that value in a call to B.g, which takes a value of B.variant_type as an input.

Is there any way to tell OCaml that A.variant_type and B.variant_type are really the same type, and thus it’s okay to convert a value from one to the other? The libraries are independent, so they should not reference each other. Right now I’m using Obj.magic to do the conversion, but this is a hack.

  • 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-29T19:12:30+00:00Added an answer on May 29, 2026 at 7:12 pm

    You dont have to use Obj.magic, although you do have to use some “magic”,

    external convertAB : A.t -> B.t = "%identity"
    external convertBA : B.t -> A.t = "%identity"
    

    is enough to do the conversion. Of course, I understand your concern; both types must be exactly the same else you’ll be dealing with run-time errors. If it’s at all possible and relevant, converting those variants to Polymorphic Variants would solve the problem.

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

Sidebar

Related Questions

I am building a CAD-file converter on top of two libraries (Opencascade and DWF
I'm building an asp.net cutom control inside which I have two dropdownlists: companyIdSelection and
Ok. So I'm building this site which is accessible through two different domains. So
I've stumbled over a seemingly simple problem while building two libraries and test programs
I'm am currently building two custom validators that extends Zend_Validate_Abstract which are named respectively
I'm building a range between two numbers (floats) and I'd like this range to
In .NET there are two version numbers available when building a project, File Version
I am building an content serving application composing of a cluster of two types
I'm building a utility application that synchronizes files across two systems for Mac OSX.
I am building a web application using ASP.NET MVC that has two very distinct

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.