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

post about string literal types #227

Merged
merged 6 commits into from
Aug 3, 2020
Merged

post about string literal types #227

merged 6 commits into from
Aug 3, 2020

Conversation

bobzhang
Copy link
Collaborator

No description provided.

@vercel vercel bot temporarily deployed to Preview July 28, 2020 03:05 Inactive
Copy link
Contributor

@yawaramin yawaramin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

With string literal types, you can do things like this:

```reasonml
[ 3 -> `Int , "3" -> `String ]
Copy link

@jfrolich jfrolich Jul 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest not using -> sugar but plain poly variants for clarity

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, would be a lot clearer without the ->

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to illustrate the idea of tagging assuming people have no background with polyvar

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is tagging?

{ NAME: "String", VAL : "3"}
```

And you can also write code to process such collections:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is the same when there are string poly variants or not. Why is this relevant to string poly variants?

The NAME now converts to a string. But why is that helpful for interop? It seems an implementation detail that doesn't have a practical use case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is used to mix data of diffrent types in a collection in a convenient way

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but that was always possible with polyvars right? So I don't know how this relates with to the announcement that they now convert to strings in some cases.


## Further reading

Here we only cover some basic usage of string literal types, user can refer [here](https://caml.inria.fr/pub/docs/manual-ocaml/lablexamples.html#s%3Apolymorphic-variants) for more advanced stuff. The type theory is almost the same, however, we adapt it to make sure it's compiled into string literals to match the JS runtime.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to explicitly note what is different compared to ocaml poly variants in the new bucklescript implementation. People might land at this blog post when running into the limitations. Even if it's just a footnote or a link to a detailed overview of the differences.

_blogposts/compiler/string-literal-types-in-reason.mdx Outdated Show resolved Hide resolved
_blogposts/compiler/string-literal-types-in-reason.mdx Outdated Show resolved Hide resolved
_blogposts/compiler/string-literal-types-in-reason.mdx Outdated Show resolved Hide resolved
_blogposts/compiler/string-literal-types-in-reason.mdx Outdated Show resolved Hide resolved
_blogposts/compiler/string-literal-types-in-reason.mdx Outdated Show resolved Hide resolved
_blogposts/compiler/string-literal-types-in-reason.mdx Outdated Show resolved Hide resolved
_blogposts/compiler/string-literal-types-in-reason.mdx Outdated Show resolved Hide resolved

## Further reading

Here we only cover some basic usage of string literal types, user can refer [here](https://caml.inria.fr/pub/docs/manual-ocaml/lablexamples.html#s%3Apolymorphic-variants) for more advanced stuff. The type theory is almost the same, however, we adapt it to make sure it's compiled into string literals to match the JS runtime.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's -> it is

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, there is a difference here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In technical writing it is better to avoid contractions. It is considered informal, conversational.

@jfrolich
Copy link

One thing that might be confusing is that the examples are now using reason syntax instead of the new Bucklescript syntax. Perhaps it makes sense to have both syntaxes in the blog post and people can select which syntax they'd like to see?

@bobzhang
Copy link
Collaborator Author

One thing that might be confusing is that the examples are now using reason syntax instead of the new Bucklescript syntax. Perhaps it makes sense to have both syntaxes in the blog post and people can select which syntax they'd like to see?

yeah, we will use the new syntax in the future, it's not settled yet

@bobzhang
Copy link
Collaborator Author

bobzhang commented Jul 28, 2020 via email

@jfrolich
Copy link

jfrolich commented Jul 28, 2020

it’s a generalization to string literal types. This post is written to people who have background in typescript

I would suggest to say that Polymorphic Variants correspond to string literals in typescript in the introduction, and then continue talking about Polymorphic Variants to not confuse anyone (and now it's clear for people coming from typescript). String literal are a less powerful construct in typescript.

Maybe have a more explicit introduction for typescript people. Something like this:

If you are coming from TypeScript you might be familiar with the string literal type. This allows you to enforce certain string values by the type checker. This functionality is now also available in BuckleScript. Polymorphic Variants without a constructor now compile to strings in JavaScript.

You can also link to the documentation of polymorphic variants in the introduction.

@bobzhang
Copy link
Collaborator Author

bobzhang commented Jul 28, 2020 via email

@jfrolich
Copy link

jfrolich commented Jul 28, 2020

Let’s agree to disagree. String literal types is a well known feature in typescript. The purpose of this project is to make some academic ideas more accessible to average users.

I get the goal you are trying to achieve. But if you'd like to achieve this, communication is important. There are a few things structurally wrong here. If you think that the term polymorphic variant is too hard to understand for beginners, it makes sense to rename these concepts. BUT this should be done deliberately, and everywhere. If you refer to the same concept with different terms in different places, this makes it objectively harder to understand for beginners. So using a different term just in a blog post off-hand is not making things clearer at all.

Also even if we would update all documentation to use this different term I don't think string literal is the best term to replace polymorphic variants for the following reason:

  • A poly variant can have a constructor, a "string literal" with a constructor doesn't make much sense

  • We should also rename variant. And what do we do when variants will also compile to strings?

If the naming of language primitives are changed this is a major thing and the transition should be communicated clearly. Honestly, I can name more than 10 different things that make it hard for beginners to get started on BuckleScript, and they are all more important than what specific language primitives are called in the language.

I would strongly suggest discussing these things with more people. Because they might seem to make things more understandable for you, confusing communication can be very frustrating for new users and even existing users. I think this is an amazing project but there have been a number of occasions where confusing communication has been driving away users. I love to help with this. And there are a number of strong communicators in the community who can also help with this.

@jfrolich
Copy link

Aside from this, I think it's better to link to ReasonML documentation for polymorphic variants than linking to OCaml. The people who already understand Reason + OCaml would not need the link and it would be confusing for people that start out with ReasonML.

@bobzhang
Copy link
Collaborator Author

hi @jfrolich your feedback is appreciated. I did have lots of communications (both online and offline), almost half my time is spent in communications -- I really hope not. At the end of day, we need make decisions.

Co-authored-by: Patrick Stapfer <ryyppy@users.noreply.github.com>
@bobzhang bobzhang merged commit 1c76855 into master Aug 3, 2020
@bobzhang bobzhang deleted the string_literal_types branch August 3, 2020 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants