-
-
Notifications
You must be signed in to change notification settings - Fork 666
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
Explore representing atoms using extensible or polymorphic variants #66
Comments
In OCaml there are both extensible variants and polymorphic variants. Polymorphic variants with no data are like atoms on the BEAM. In OCaml they are of the form `Head like: `Blah
`Bloop
`CanAlsoHoldData 42 And they are typed into function as either open typed or closed typed, depending on whether it takes/returns possible extras or a restricted set. Extensible variants are first given a type name then they can be added to, like: (* The `..` means it is an extensible variant *)
type blah = ..
(* Add a single head *)
type blah += Str of String
(* Add multiple heads at once *)
type blah +=
| Int of int
| Float of float I'm thinking the global polymorphic variants are more like BEAM Atoms, though of course a normal data-less variant head of any form would compile down to just an atom anyway. |
For note, OCaml's Exception type is an extensible variant named type exn += MyException of WhateverData Since each head+datatype is its own unified type then you can even reuse an existing head if it makes sense for the given exception, like the base Exception type exn += Exc of MyModule.MyException.t That way people can catch it without knowing about it if they have a default datatype handler but don't want to set an overall default handler. An extensible variant in OCaml can even be defined as private like: type blah = private .. That means that only the current module where it is defined (and any modules defined within) can add to it, but they can still be referenced via interfaces. |
Thanks for the info, very useful. OCaml has been a huge influence though I don't know the language in any great detail.
I think you're right and I got my terminology mixed up. |
tomprimozic/type-systems@4403586
The text was updated successfully, but these errors were encountered: