~fgaz/pointfree-ghcjs

d278a90df951f0cd299d270562059547102613e1 — Francesco Gazzetta 1 year, 2 months ago
🌅
4 files changed, 94 insertions(+), 0 deletions(-)

A LICENSE
A Main.hs
A README.md
A pointfree-ghcjs.cabal
A  => LICENSE +30 -0
@@ 1,30 @@
Copyright (c) 2022, Francesco Gazzetta

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.

    * Neither the name of Francesco Gazzetta nor the names of other
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

A  => Main.hs +38 -0
@@ 1,38 @@
{-# LANGUAGE OverloadedStrings #-}
import GHCJS.Types (JSVal, JSString)
import Data.JSString (pack, unpack)
import GHCJS.Foreign.Callback (Callback, asyncCallback)
import Pointfree (pointfree')
import Data.Maybe (fromMaybe)

foreign import javascript
  "document.getElementById($1)" getElementById :: JSString -> IO JSVal

foreign import javascript
  "$1.onclick = $2" setOnclick :: JSVal -> Callback (IO ()) -> IO ()

foreign import javascript
  "$1.value" getValue :: JSVal -> IO JSString

foreign import javascript
  "$1.textContent = $2" setTextContent :: JSVal -> JSString -> IO ()

foreign import javascript
  "document.body.innerHTML = $1" setBodyHTML :: JSString -> IO ()

body :: JSString
body = "<input type='text' id='input' />"
    <> "<button id='btn'>Pointfree!</button>"
    <> "<div id='output'>Output will appear here</div>"
    <> "<div><p>Source: <a href='https://sr.ht/~fgaz/pointfree-ghcjs'>sr.ht/~fgaz/pointfree-ghcjs</a></p></div>"

main :: IO ()
main = do
  setBodyHTML body
  btn <- getElementById "btn"
  input <- getElementById "input"
  output <- getElementById "output"
  callback <- asyncCallback $ do
    v <- getValue input
    setTextContent output $ pack $ fromMaybe "Invalid expression!" $ pointfree' $ unpack v
  setOnclick btn callback

A  => README.md +4 -0
@@ 1,4 @@
# pointfree-ghcjs

A simple wrapper that runs [pointfree](https://hackage.haskell.org/package/pointfree) in the browser.
Made after [pointfree.io](https://pointfree.io) went offline. 

A  => pointfree-ghcjs.cabal +22 -0
@@ 1,22 @@
cabal-version:      3.0
name:               pointfree-ghcjs
version:            0.1.0.0
synopsis:           Run pointfree in the browser
description:        A simple wrapper that runs <https://hackage.haskell.org/package/pointfree> in the browser.
license:            BSD-3-Clause
license-file:       LICENSE
author:             Francesco Gazzetta
maintainer:         fgaz@fgaz.me
copyright:          2022 Francesco Gazzetta
category:           Web
build-type:         Simple
tested-with:        GHCJS == 8.10.7

executable pointfree-ghcjs
    ghc-options: -Wall
    main-is:          Main.hs
    other-extensions: OverloadedStrings
    build-depends:    base ^>=4.14.3.0
                    , ghcjs-base ^>=0.2.1.0
                    , pointfree ^>=1.1.1.9
    default-language: Haskell2010