Skip to content

Instantly share code, notes, and snippets.

@szobov
Created September 19, 2017 05:58
Show Gist options
  • Save szobov/fbc2c684f7ecc862f2d3ea03f810a365 to your computer and use it in GitHub Desktop.
Save szobov/fbc2c684f7ecc862f2d3ea03f810a365 to your computer and use it in GitHub Desktop.
We've found a bug for you!
/home/foo/dev/reason-tryies/src/index.re
1 │ external mediumEditor : string => 'a => 'b = "medium-editor" [@@bs.mod
ule][@@bs.new];
2 │ external extend: 'a => 'b = "" [@@bs.module "medium-editor"][@@bs.scop
e "Extension"];
3 │ let _ext = {
4 │ "name": "myext",
5 │ "init": (fun that => {
6 │ that##subscribe ();
7 │ Js.log "Here"
8 │ }),
9 │ "foo": (fun () => Js.log "Hello!")
10 │ };
11 │
12 │ let extension = extend _ext;
This expression's type contains type variables that can't be generalized:
Js.t
{. foo : unit => unit,
init : Js.t {_.. subscribe : Js.Internal.meth [ `Arity_0 ] '_a } => unit,
name : string }
This happens when the type system senses there's a mutation/side-effect, in combination with a polymorphic value.
Using or annotating that value usually solves it. More info:
https://realworldocaml.org/v1/en/html/imperative-programming-1.html#side-effects-and-weak-polymorphism
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment