Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Variables in Native Toplevel #1

Closed
NathanReb opened this issue Nov 22, 2021 · 2 comments
Closed

Type Variables in Native Toplevel #1

NathanReb opened this issue Nov 22, 2021 · 2 comments

Comments

@NathanReb
Copy link
Owner

The native toplevel does not retain type var names as the bytecode toplevel does. When a type with type parameters is defined in a native toplevel session, with those parameters explicitly named, future evaluation may not retain this name and use the regular 'a, 'b, etc. instead.

Here's an example, taken from ocaml-jit's test suite:

# module A : sig 
    type ('foo, 'bar) t

    val get_foo : ('foo, _) t -> 'foo option
  end = struct
    type ('foo, 'bar) t =
      | Foo of 'foo
      | Bar of 'bar

    let get_foo = function
      | Foo foo -> Some foo
      | Bar _ -> None
  end
  ;;
module A :
  sig type ('foo, 'bar) t val get_foo : ('foo, 'a) t -> 'foo option end
# A.get_foo;;
- : ('foo, 'a) A.t -> 'foo option = <fun>

This is what you get in a bytecode toplevel, the 'foo type variable is preserved in the toplevel evaluation of A.get_foo. Running the same phrases in a native toplevel would get you:

- : ('a, 'b) A.t -> 'a option = <fun>

This has been fixed in ocaml-flambda/flambda-backend#188.

The upstream patch is awaiting review here ocaml/ocaml#10712.

@dra27
Copy link

dra27 commented Jan 5, 2022

This is fixed in 4.14!

@NathanReb
Copy link
Owner Author

Wonderful, thanks for taking care of this!

The Native MDX Experience automation moved this from In progress to Done Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants