CARVIEW |
Select Language
HTTP/2 200
date: Thu, 31 Jul 2025 09:18:49 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-robots-tag: none
etag: W/"5fff77d2180a501a65658106be3e85fc"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com wss://alive-staging.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=OMnUktFSAtk5q33cAZLHTb7fp2PEeLRmqMFx2q93vhxUXO6LEjznHYCQiyhNmuoRePaAO%2BJTTR7RAiyB%2FJXOEGEKoaOSuNfWiUqTpOxZfUuMyb%2FhqxQcZ2bLwTxj%2F4shUMCnXrpCcY4JYUFYYqxKro9YG3S9ImlsnfsFrl7Q2GZ3Je14kYpp1MzWBvyLz73cRuxrhi8wEQyq%2FVLFngP5gJlH8dlm32SkXBA9NH9okr%2F%2FDsjgRB2Owbgj3zga9LLwJHNmHYoECKWvdungV4auXg%3D%3D--cZCW8D8KFtJSwLPS--lzwR1%2F%2FCpRgaq1TNfZJ4EA%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.3604599.1753953529; Path=/; Domain=github.com; Expires=Fri, 31 Jul 2026 09:18:49 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Fri, 31 Jul 2026 09:18:49 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: BB50:1EF490:6DB9A6:863097:688B34F9
Wrapping OCaml WrapOCaml.ml · FStarLang/FStar Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 241
Wrapping OCaml WrapOCaml.ml
briangmilnes edited this page Sep 16, 2024
·
1 revision
(*
This module shows all of the basic types you'll need going into and out of OCaml,
correctly typed in both and fsti interface and an mli interface. In the ml we
show how to transform everything into the native OCaml and back to the right
type to return to F*.
*)
let unit_to_unit (u : unit) : unit = ()
let bool_to_bool (b : bool) : bool = b
let float_to_float (f : float) : float = f
(* It is difficult to get a char across to ML, int is easiest.
Even though we can then make an unsigned Char of it from
the newer module Uchar.t
*)
let char_to_char (c : int) : int = c
let uchar_to_uchar (c : int) : int = (Uchar.to_int (Uchar.of_int c))
let byte_to_byte (b : FStar_Bytes.byte) : FStar_Bytes.byte = b
let int_to_int (i : Z.t) : Z.t = Z.of_int ((Z.to_int i) + 1)
let string_to_string (s : string) : string = (s ^ " There!")
let option_to_option (o : Z.t option) : Z.t option =
match o with
| None -> None
| Some x -> Some x
let list_to_list (l : Z.t list ) : Z.t list =
match l with
| [] -> []
| h::t -> t
(* Here are unsafe translation to and from int. *)
let int8_to_int8 (i : FStar_Int8.int8) : FStar_Int8.int8 =
(FStar_Int8.of_native_int (FStar_Int8.to_native_int i))
let uint8_to_uint8 (i : FStar_UInt8.uint8) : FStar_UInt8.uint8 = i
let uint16_to_uint16 (u : FStar_UInt16.uint16) : FStar_UInt16.uint16 =
(FStar_UInt16.of_native_int (FStar_UInt16.to_native_int u))
let int16_to_int16 (i : FStar_Int16.int16) : FStar_Int16.int16 =
(FStar_Int16.of_native_int (FStar_Int16.to_native_int i))
let int32_to_int32 (i : FStar_Int32.int32) : FStar_Int32.int32 =
(FStar_Int32.of_native_int (FStar_Int32.to_native_int i))
let uint32_to_uint32 (u : FStar_UInt32.uint32) : FStar_UInt32.uint32 =
(FStar_UInt32.of_native_int (FStar_UInt32.to_native_int u))
let int64_to_int64 (i : FStar_Int64.int64) : FStar_Int64.int64 =
(FStar_Int64.of_native_int (FStar_Int64.to_native_int i))
let uint64_to_uint64 (u : FStar_UInt64.uint64) : FStar_UInt64.uint64 =
(FStar_UInt64.of_native_int (FStar_UInt64.to_native_int u))
(* At this point I don't know how to translate this. *)
let int128_to_int128 (i : FStar_Int128.t) : FStar_Int128.t = i
let uint128_to_uint128 (u : FStar_UInt128.t) : FStar_UInt128.t = u
(* In FStar_Bytes.ml this is a string and we can treat it as such.
But we are also translate it to OCaml bytes, set it, and
return it as a string. Both FStar and OCaml are treating this
as immutable, so some OCaml wrapped calls have to change to
return the byte array as a string.
*)
let bytes_to_bytes (b : FStar_Bytes.bytes) : FStar_Bytes.bytes =
let len = String.length b in
let bs = Bytes.of_string b in
Bytes.set bs 0 'H';
Bytes.set bs 1 'I';
Bytes.to_string bs
(* Take an enum from another module and show its translation. *)
module Enum' = struct
type enum = | One | Two
end
type enum = | One | Two
let of_enum (e : enum) : Enum'.enum =
match e with
| One -> Enum'.One
| Two -> Enum'.Two
let to_enum (e : Enum'.enum) : enum =
match e with
| Enum'.One -> One
| Enum'.Two -> Two
let enum_to_enum (e : enum) : enum = to_enum (of_enum e)
(* You can simply use an inductive type if you've defined it in
F* and your OCaml, but the more common case is you're wrapping
an exception from OCaml into one in F*.
*)
type prime = | Three | Seven
let prime_to_prime (e: prime) : prime = e
(*
You can translate an exception and type a function on it in OCaml but
not in F*.
*)
(* Exceptions *)
module HasExn = struct
exception Bad of string
end
exception Bad of string
let to_bad e =
match e with
| HasExn.Bad s -> Bad s
| _ -> raise (Failure "Not a bad exception.")
let of_bad e =
match e with
| Bad s -> HasExn.Bad s
| _ -> raise (Failure "Not a bad exception.")
let bad_to_bad (e : exn) : exn = (to_bad (of_bad e))
You can’t perform that action at this time.