uu-computerscience / uhc-js Goto Github PK
View Code? Open in Web Editor NEWThis project forked from norm2782/uhc-jscript
This project forked from norm2782/uhc-jscript
Running listToStrictJSArray [1,2,3]
results in the error Uncaught ReferenceError: primStrictWriteArray is not defined
(at runtime in the browser).
I'm using ehc-1.1.3, Revision 2422:2426M but the sources at https://github.com/UU-ComputerScience/uhc/blob/master/EHC/src/javascript/rts/prim.cjs don't have a definition either.
listToJSArray [1,2,3] :: JSArray Int
should result in [1,2,3]
but the actual result is [3,2,1]
.
These two technologies are most useful when making non-HTML document based applications.
Foreign interface would enable UHC-JS to support common use cases of drawing applications.
Note that requires support for typed arrays for WebGL to be effective.
Bang Patterns were one of two most effective optimization techniques introduced by Clean research team (along with unique types), and are one that is most used in common Haskell programs besides unboxed types.
Implementing syntax support for these may greatly increase number of Cabal packages that may compile under UHC/UHC-JS.
The following works:
module Main where
import Language.UHC.JS.Primitives
foreign import js "wrapper"
wrap :: IO () -> IO (JSFunPtr (IO ()))
foreign import js "window.addEventListener('load', %1)"
onLoad :: JSFunPtr (IO ()) -> IO ()
main :: IO ()
main = do
wrap $ do
alert "Hello"
>>= onLoad
If I move wrap
and onLoad
to a separate module:
Wrap.hs:
module Wrap where
import Language.UHC.JS.Primitives
foreign import js "wrapper"
wrap :: IO () -> IO (JSFunPtr (IO ()))
foreign import js "window.addEventListener('load', %1)"
onLoad :: JSFunPtr (IO ()) -> IO ()
Main.hs:
module Main where
import Language.UHC.JS.Primitives
import Wrap
main :: IO ()
main = do
wrap $ do
alert "Hello"
>>= onLoad
I receive a JavaScript runtime error:
Uncaught TypeError: Cannot call method '__aN__' of undefined
I am trying to get this example to work:
Here is my source file:
module Hello where
import Language.UHC.JS.Prelude
import Language.UHC.JS.Assorted
import Language.UHC.JS.W3C.HTML5
--data Document
--foreign import js "document" document :: IO Document
--foreign import js "%1.write()" documentWrite :: Document -> JSString -> IO ()
--foreign import js alert :: JSString -> IO ()
--
--foreign import js "%1.getElementsByName()" documentGetElementsByName :: Document -> JSString -> IO (NodeList Node)
--
--data NodeList x
--
--foreign import js "%1.length" nodeListLength :: NodeList Node -> Int
--foreign import js "%1[%2]" nodeListItem :: NodeList Node -> Int -> IO Node
--
--data Node
--
--foreign import js "%1.innerHTML" elementInnerHTML :: Node -> JSString
--foreign import js "%1.tagName" elementTagName :: Node -> JSString
main = do d <- document
n <- documentGetElementById d (stringToJSString "myHeader")
alert $ jsStringToString $ elementTagName n
alert $ jsStringToString $ elementInnerHTML n
I compile using uhc --import-path=uhcjs/uhc-js/src --target=js -O,2 jsffi.hs
.
Then, I add an element using echo "<div id='myHeader'>test</div>" >> jsffi.html
and then I open jsffi.html. Nothing is alerted.
I tried the example without uhc-js, that did not work either. What could be the problem?
I was trying to use newObj "Image"
to get an HTML Image object, but the object that was created wasn't a proper Image. It was an object but it was mostly empty.
I think the problem is in primMkObj - it's doing
return new primGetCtor(nm);
I think what's happening is the new
here is treating primGetCtor itself as the constructor function, and the actual constructor that primGetCtor returns is just being ignored.
I can fix it by adding parentheses:
return new (primGetCtor(nm))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.