You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.
However, there is also the problem of serializing ADT's to JSON, which I think will be pretty common when communicating with a remote server. I'd like to suggest perhaps considering an encoding that includes the constructors?
E.g. Possibly something in the style of
with
data NestedADT = NestedConstructor Number
data ADT = Constructor Number Number NestedADT
The [[Class]] solution has its own problem, which is that it's only doing string comparison. In contrast, instanceof checks actual references, so it's less prone to false positives.
I propose that serialization and deserialization with type information is not something Roy should try to automate at a language level. Instead, that should be left to libraries such as HydrateJS.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi! I noticed that roy uses 'instanceof' quite pervasively, especially for pattern-matching ADT's.
Instanceof tends to have trouble when doing cross-framescripting and I suspect also in webworkers etc.
One possible solution is to leverage the internal [[CLASS]] property instead as suggested by various by people around the web:
http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/
http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/
http://tobyho.com/2011/01/28/checking-types-in-javascript/
However, there is also the problem of serializing ADT's to JSON, which I think will be pretty common when communicating with a remote server. I'd like to suggest perhaps considering an encoding that includes the constructors?
E.g. Possibly something in the style of
with
then this
might be represented as
or perhaps differentiating between constructors that take multiple arguments and constructors that take a single argument
on the other hand, simply using arrays might be faster?
...in which case the code to match the nested constructors might need to do something like
Which I suspect should also be pretty efficient given that Array.isArray is a native function (pure speculation though).
P.S. Perhaps it is useful to support a similar pattern matching mechanism for Lists and ADT's in order to make the generated js look uniform?
e.g.
Cheers,
Rehno
The text was updated successfully, but these errors were encountered: