From 5765b6bb1fdb2c20a3e54a3efad1584154bd970b Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Wed, 28 Dec 2011 10:30:37 -0500 Subject: More about the JavaScript FFI in the manual --- doc/manual.tex | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/manual.tex b/doc/manual.tex index 82bd5244..1a8e79ff 100644 --- a/doc/manual.tex +++ b/doc/manual.tex @@ -2339,13 +2339,33 @@ In contrast to C FFI code, JavaScript FFI functions take no extra context argume \begin{itemize} \item Integers, floats, strings, characters, and booleans are represented in the usual JavaScript way. -\item Ur functions are represented in an unspecified way. This means that you should not rely on any details of function representation. Named FFI functions are represented as JavaScript functions with as many arguments as their Ur types specify. To call a non-FFI function \texttt{f} on argument \texttt{x}, run \texttt{execF(f, x)}. +\item Ur functions are represented in an unspecified way. This means that you should not rely on any details of function representation. Named FFI functions are represented as JavaScript functions with as many arguments as their Ur types specify. To call a non-FFI function \texttt{f} on argument \texttt{x}, run \texttt{execF(f, x)}. To lift a normal JavaScript function \cd{f} into an Ur/Web JavaScript function, run \cd{flift(f)}. \item An Ur record is represented with a JavaScript record, where Ur field name \texttt{N} translates to JavaScript field name \texttt{\_N}. An exception to this rule is that the empty record is encoded as \texttt{null}. \item \texttt{option}-like types receive special handling similar to their handling in C. The ``\texttt{None}'' constructor is \texttt{null}, and a use of the ``\texttt{Some}'' constructor on a value \texttt{v} is either \texttt{v}, if the underlying type doesn't need to use \texttt{null}; or \texttt{\{v:v\}} otherwise. \item Any other datatypes represent a non-value-carrying constructor \texttt{C} as \texttt{"C"} and an application of a constructor \texttt{C} to value \texttt{v} as \texttt{\{n:"C", v:v\}}. This rule only applies to datatypes defined in FFI module signatures; the compiler is free to optimize the representations of other, non-\texttt{option}-like datatypes in arbitrary ways. \end{itemize} -It is possible to write JavaScript FFI code that interacts with the functional-reactive structure of a document, but this version of the manual doesn't cover the details. +It is possible to write JavaScript FFI code that interacts with the functional-reactive structure of a document. Here is a quick summary of some of the simpler functions to use; descriptions of fancier stuff may be added later on request (and such stuff should be considered ``undocumented features'' until then). + +\begin{itemize} +\item Sources should be treated as an abstract type, manipulated via: + \begin{itemize} + \item \cd{sc(v)}, to create a source initialized to \cd{v} + \item \cd{sg(s)}, to retrieve the current value of source \cd{s} + \item \cd{sv(s, v)}, to set source \cd{s} to value \cd{v} + \end{itemize} + +\item Signals should be treated as an abstract type, manipulated via: + \begin{itemize} + \item \cd{sr(v)} and \cd{sb(s, f)}, the ``return'' and ``bind'' monad operators, respectively + \item \cd{ss(s)}, to produce the signal corresponding to source \cd{s} + \item \cd{scur(s)}, to get the current value of signal \cd{s} + \end{itemize} + +\item The behavior of the \cd{} pseudo-tag may be mimicked by following the right convention in a piece of HTML source code with a type like $\mt{xbody}$. Such a piece of source code may be encoded with a JavaScript string. To insert a dynamic section, include a \cd{