This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Add support to export refs. #237
Comments
In fact, any translation would destroy the identity of the reference. |
cristianoc
added a commit
that referenced
this issue
Aug 22, 2019
#238 contains examples on how to export a reference as an abstract type, in case the argument type of the reference requires conversion: // Abstract version of references: works when conversion is required.
module R: {
[@genType]
type t('a);
let get: t('a) => 'a;
let make: 'a => t('a);
let set: (t('a), 'a) => unit;
} = {
type t('a) = ref('a);
let get = r => r.contents;
let make = ref;
let set = (r, v) => r.contents = v;
};
[@genType]
type t('a) = R.t('a);
[@genType]
let get = R.get;
[@gentype]
let make = R.make;
[@genType]
let set = R.set;
type requiresConversion = {x: int};
// Careful: conversion makes a copy and destroys the reference identity.
[@genType]
let destroysRefIdentity = (x: ref(requiresConversion)) => x;
// Using abstract references preserves the identity.
[@genType]
let preserveRefIdentity = (x: R.t(requiresConversion)) => x; |
cristianoc
added a commit
that referenced
this issue
Aug 22, 2019
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The translation should do the equivalent of this:
gives
The text was updated successfully, but these errors were encountered: