[Ur] Announcing jsMove
Adam Chlipala
adamc at impredicative.com
Sun Jul 22 08:27:20 EDT 2012
Thanks for the nice example!
I think the mouse/key event handler changes I announced yesterday might
make some (but definitely not all) of your FFI work redundant.
Why does jsMove.urs include type definitions?
I notice many redundant parentheses in jsMove.ur, which is
understandable for someone new to ML-style syntax (if you are?), but
which still confuses me, since I assume parens are there for a reason. ;)
You define a function [showXY] that would be an excellent candidate for
a [show] type class instance, so that you could afterward call merely
[show] instead of [showXY].
There is a [source] holding a [string] that gives instructions for the
user. Currently, an 'onload' handler computes this string imperatively
and stores it in the [source]. A more idiomatic Ur/Web approach would
be to code the instructions part of the page as a <dyn> that refers
directly to the underlying data sources (in this case, [mouseOn] and
[clickToMove]). This also saves you some code duplication, as currently
you recompute the instructions in the same way in multiple locations.
Clearly it is worth defining a function for the pattern [x <- signal x;
return <xml>{[x]}</xml>], in some common library. :-)
You use the constructor [Cons] directly in one place. I prefer the
infix operator [::] for that.
Timothy Beyer wrote:
> I recently implemented a simple Ur/Web application "jsMove" which draws a
> circle to the screen. The circle may be moved interactively via keyboard/mouse
> or touchscreen, depending on the selected URL (main or main_touch). It uses
> the Ur/Web JavaScript FFI extensively for graphics (Raphaël) and for several
> additional event handlers.
>
> It is mainly targeted towards people who are completely new to Ur/Web and don't
> understand how to use the JavaScript FFI very well, or people who want to write
> non-traditional web applications (eg. games, desktop style applications) in a
> browser.
>
> Keep in mind that the code is ugly because I haven't mastered the type system
> yet, so any critiques are welcome. There are also currently some issues with
> pressing the buttons with the mouse, but for the most part the code works very
> well and could likely be useful to others.
>
> The complete source code is available:
> http://chiselapp.com/user/beyert/repository/urweb_examples/urweb_examples
More information about the Ur
mailing list