ghcjs

How do you convert from an Unboxed Vector to a JS TypedArray on GHCJS?

只愿长相守 提交于 2019-12-05 13:14:51
I have an element of type Data.Vector.Unboxed.Vector Word32 . I want to convert that to a native JS TypedArray (an Uint32Array , specifically). I'm aware of toJsArray and toJsValListOf , but both functions deal with lists, not vectors, and are inefficient. How can I convert an unboxed Vector directly to a JS TypedArray ? I was able to solve this up to marshalling to an Int32Array instead of an Uint32Array ; probably someone who has actually known GHCJS for more than the one hour I've put into this will be able to expand on this so that you get your Uint32Array (or you can just make a hacked-up

XhrRequest with reflex/reflex-dom

放肆的年华 提交于 2019-12-04 04:21:55
I want to perform a basic Ajax request, that's all. I use reflex for the frontend and Scotty for the backend. The Firefox Web Console tells me the request was a success and I see the expected result there. But the website switches from Just "default" to Nothing instead of Just "success!" . Here is a complete minimal example: import Reflex (holdDyn) import Reflex.Dom (button, el, mainWidget, display) import Reflex.Dom.Xhr (performRequestAsync, xhrRequest, decodeXhrResponse) import Reflex.Class (tag, constant) import Data.Default (def) main :: IO () main = do mainWidget $ el "div" $ do

Creating a Behavior for a continuously measurable phenomenon

夙愿已清 提交于 2019-12-04 02:34:01
I would like to create a Behavior t a from an IO a , with the intended semantics that the IO action would be run every time the behavior is sample d: {- language FlexibleContexts #-} import Reflex.Dom import Control.Monad.Trans onDemand :: (MonadWidget t m, MonadIO (PullM t)) => IO a -> m (Behavior t a) I hoped I could do this by just executing the measurement in a pull : onDemand measure = return $ pull (liftIO measure) However, the resulting Behavior never changes after an initial measure ment. The workaround I could come up with was to create a dummy Behavior that changes "frequently enough

Using Overloaded Strings

我们两清 提交于 2019-12-04 01:47:12
OverloadedStrings extension is really very useful, however it has some downsides. Consider the following function definition: someFunction :: ToJSSTring a => a -> IO () someFunction = js_function . toJSSTring In this case when if I want to pass a literal value I have to add a type signature explicitly when OverloadedStrings is enabled: someFunction ("This is plain string" :: String) someFunction ("And this one is Text" :: Data.Text.Text) The reason for this necessity is quite obvious, I suppose OverloadedStrings was designed to ease the passing of literal values to functions that have strict

How to call Haskell from Javascript with GHCJS

感情迁移 提交于 2019-12-03 05:48:41
问题 I've been playing about with GHCJS. The FFI can be used to call javascript from Haskell but I can't figure out how do go the other way round. Say I had a super useful utility function I wrote in Haskell: sayHello :: String -> IO () sayHello name = print $ "hello, " ++ name Is it possible do something so I could call it from Javascript? The closest I've got is noticing that h$main(h$main2CMainzimain) will trigger my Haskell main function. 回答1: Here is a way to make it work. Assume we have some

How to call Haskell from Javascript with GHCJS

南楼画角 提交于 2019-12-02 19:06:47
I've been playing about with GHCJS. The FFI can be used to call javascript from Haskell but I can't figure out how do go the other way round. Say I had a super useful utility function I wrote in Haskell: sayHello :: String -> IO () sayHello name = print $ "hello, " ++ name Is it possible do something so I could call it from Javascript? The closest I've got is noticing that h$main(h$main2CMainzimain) will trigger my Haskell main function. Here is a way to make it work. Assume we have some useful function, like revString :: String -> String revString = reverse somethingUseful :: JSString -> IO