Using javascript libraries from Haskell

I am new to Haskell. I recently heard about this GHCJ compiler, where you can write code in Haskell, which can then be compiled into Javascript.

I am interested in using libraries like three.js and webgl to create interesting interactive 3D animations. Can I call these javascript libraries from Haskell when using GHCJ?

+4
source share
1 answer

Yes, you can call Javascript libraries from ghcjs compiled by Haskell.

Here is a simple example:

{-# LANGUAGE JavaScriptFFI      #-}
{-# LANGUAGE OverloadedStrings  #-}

import qualified Data.JSString    as T
import qualified GHCJS.Foreign

foreign import javascript unsafe "alert($1)" alert :: T.JSString -> IO ()

main = alert "hello world"

As you can see from this example, you use a function foreign import javascriptto make JS functions available in your Haskell programs.

, WebGL, , - , . . foreign , .

three.js github repo:

https://github.com/manyoo/ghcjs-three

Haskell JS, .. SO:

Haskell Javascript GHCJS

+5

All Articles