Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
STG in Javascript
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Sep 12, 2006 == To simplify handling of partial function applications, format of thunk has been changed so that instead of ''_1'', ''_2'', etc. for function argument, an array named ''_a'' is used. This array always has at least one element which is ''undefined''. Arguments start with array element indexed at 1, so to access an argument ''n'', the following needs to be used: ''this._a[n]''. For Haskell programs executing in a web browser environment, analogous to FFI is calling external Javascript functions. Imagine this Javascript function which prints its argument on the window status line: <pre> // Output an integer value into the window status line putStatus = function (i) {window.status = i; return i;}; </pre> To import such a function is a Haskell program, the following FFI declaration is to be used: <pre> foreign import ccall "putStatus" putStatus :: Int -> Int </pre> Note the type signature: of course it should be somewhat monadic, but for the moment, nothing has been done to support monads, so this signature is only good for testing purposes. The current NHC98-based implementation compiles the above FFI declaration into this: <pre> Test2.putStatus_T=function(_1){return {_c:Test2.putStatus_C, _w:"7:1-7:56", _a:[undefined, _1]};}; Test2.putStatus_C=function(){ return (putStatus)((this._a[1])._c()); }; </pre> Note that like a primitive, a foreign function evaluates all its arguments before it starts executing. A test page illustrating this can be found at: http://www.golubovsky.org/repos/nhcjs/test2.html When this page is loaded, the window status line should display "456" while the rest of the page remains blank. The Haskell source for this test page is: http://www.golubovsky.org/repos/nhcjs/test2.hs
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width