Interoperability with browsers, Javascript libraries etc.

79 views
Skip to first unread message

Robin Green

unread,
May 3, 2012, 2:04:57 PM5/3/12
to roy...@googlegroups.com
Does Roy support this yet? If so, how does it work? How does it know what the names and types of the available things are?

Brian McKenna

unread,
May 6, 2012, 8:38:38 PM5/6/12
to roy...@googlegroups.com
It's definitely supported - you can try it out on http://roy.brianmckenna.org/

The most interesting example would be jQuery deferred:

https://raw.github.com/pufuwozu/roy/master/examples/deferredmonad.roy

The problem is that accessing names that Roy doesn't know about falls
back to dynamic typing. That makes it easy to access things like
jQuery.

If you take a look at the Roy REPL - unknown things are typed as "Native".

roy> console
{} : Native

Any "Native" type can be implicitly coerced to a different type, like so:

roy> let f: Number = console
roy> f
{} : Number

(treating console as a Number is of course broken)

So, you have to be careful when interoperating because it falls back
to dynamic typing. But it's easy to give a statically typed API to the
external stuff and use that instead.

My advice is to separate pure Roy code from native JavaScript calls as
much as possible. Hopefully that will mostly be possible when I
implement a good standard library.

Also, another problem with this approach is that you can make typos
and Roy doesn't tell you that it has fallen back to dynamic typing.
I'm going to make it so that a warning is shown when you access
something that Roy doesn't know about. People wanting to enforce more
"correctness" can treat that warning as an error for their pure Roy
modules.

Hopefully that makes some sense. Please let me know what you think
about the approach.

Thanks,
Brian
Reply all
Reply to author
Forward
0 new messages