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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:37:03+00:00 2026-06-11T05:37:03+00:00

I am converting the OCaml Format module to F#; see my earlier question .

  • 0

I am converting the OCaml Format module to F#; see my earlier question.

To get started I changed

type size

external size_of_int : int -> size = "%identity"

external int_of_size : size -> int = "%identity"

to

let size_of_int = sizeof<int>

and a few other adjustments which I know is not correct, but it allowed me to convert all code related to open_box and close_box expect these three lines.

Now I have to just change these three lines so that I can test the subset of the format module that I did convert.

I know that the lines with size_of_int and int_of_size while external will probably rely on some function in the F# core. I also know that %identity can probably be ignored for the conversion.

My best guess is that I only need to create a simple type named size with size_of_int and int_of_size, but how?

EDIT

Based on answer by Jeffrey Scofield I was able to create the following F# code.

type size =
  interface
    abstract size_of_int : int -> size
    abstract int_of_size : size -> int
  end

type size = int
let size_of_int i = i
let int_of_size s = s

which allowed my subset of the Format module to successfully compile.

EDIT

Jack, who answered below, has a version at FSharpx.Compatibility.OCaml.Format.Format.fs
I havent’ tested it, but it is the most compelete version I have found at present.

  • 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-11T05:37:04+00:00Added an answer on June 11, 2026 at 5:37 am

    These lines:

    type size
    external size_of_int : int -> size = "%identity"
    external int_of_size : size -> int = "%identity"
    

    Create an abstract type that is identical to int. The conversion functions
    are no-ops (the identity function). I don’t know the F# idioms, but in
    OCaml you can use an interface file and avoid the cleverness with “%identity”.

    (* Interface file *)
    type size
    val size_of_int : int -> size
    val int_of_size : size -> int
    
    (* Implementation file *)
    type size = int
    
    let size_of_int i = i
    let int_of_size s = s
    

    Hopefully this translates more readily into F#.

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

Sidebar

Related Questions

Converting json to oher type should be easy. From the Play! documentation : var
After converting to Visual Studio 2010 with ReSharper5 some of my unit tests started
Converting dates/times into ticks using the PowerShell Get-Date applet is simple. However, how do
I am converting several modules based on OCaml to F# and ran into the
I am converting several modules based on OCaml to F# and ran into something
I am converting several modules based on OCaml to F#. I have the code
After converting an ASP.NET webform (v3.5) to use a master page, I started getting
Converting numbers from double-precision floating-point format to single-precision floating-point format results in loss of
Im converting some information Im receiving by a string to a float to get
While converting a collection to a capped collection last night, my secondary's optime started

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.