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.
These lines:
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”.
Hopefully this translates more readily into F#.