Skip to content

Instantly share code, notes, and snippets.

@luite
luite / XhrB.hs
Created May 27, 2015 16:33
XHR with interruptible FFI
{-# LANGUAGE JavaScriptFFI #-}
module XhrB (xhr) where
import GHCJS.Types
import Control.Exception (onException)
data XHR_
type XHR = JSRef XHR_
@luite
luite / Main.hs
Created March 21, 2015 11:35
Client side points free with GHCJS
{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables, Rank2Types, JavaScriptFFI, OverloadedStrings #-}
module Main where
import Control.Applicative
import Control.Concurrent
import Control.Exception
import Control.Monad
import GHCJS.Types
{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI, InterruptibleFFI, EmptyDataDecls, LambdaCase, ScopedTypeVariables, DeriveDataTypeable, BangPatterns #-}
{-|
XMLHttpRequest bindings using lightweight threads and GHCJS
These bindings are incomplete and serve as an illustration for
implementing asynchronous IO on GHCJS.
author: Luite Stegeman
-}
@luite
luite / install.sh
Last active December 25, 2015 23:59
cabal-src-install dependencies
#!/bin/bash
install_src_pkg() {
wget -q "http://ghcjs.github.io/packages/cabal-src/$1/$2/$1-$2.tar.gz"
tar -xzf "$1-$2.tar.gz"
cd "$1-$2"
cabal-src-install --src-only
cd ..
}
@luite
luite / interactive.hs
Last active December 24, 2015 03:29
Interactive results for interactive-diagrams
{-# LANGUAGE TypeFamilies,
MultiParamTypeClasses,
FlexibleInstances,
UndecidableInstances,
FunctionalDependencies #-}
import Control.Concurrent
import Control.Monad
import Control.Monad.Fix
@luite
luite / B.hs
Created September 10, 2013 07:27
hooks demo with the records implementation of Hooks
{-# LANGUAGE ForeignFunctionInterface, QuasiQuotes #-}
module Main where
import Text.Blaze
import Text.Blaze.Renderer.String
import Text.Hamlet -- provided by hamlet package
foreign import ccall safe "sin" c_testImport :: Double -> IO Double
@luite
luite / B.hs
Created September 7, 2013 20:26
hooks demo, using Dynamic variant of hooks patch
{-# LANGUAGE ForeignFunctionInterface, QuasiQuotes #-}
module Main where
import Text.Blaze
import Text.Blaze.Renderer.String
import Text.Hamlet -- provided by hamlet package
foreign import ccall safe "sin" c_testImport :: Double -> IO Double
@luite
luite / B.hs
Created September 4, 2013 23:42
demonstration of the GHC Hooks API. Compile with -dynamic if you have dynamic GHC programs. Make sure that B.hs in the same directory
{-# LANGUAGE ForeignFunctionInterface, QuasiQuotes #-}
module Main where
import Text.Blaze
import Text.Blaze.Renderer.String
import Text.Hamlet -- provided by hamlet package
foreign import ccall safe "sin" c_testImport :: Double -> IO Double
@luite
luite / B.hs
Created August 22, 2013 20:04
How to use RunQuasiQuoterHook
{-# LANGUAGE QuasiQuotes #-}
module B where
import Text.Hamlet
import Text.Blaze
f :: Markup
f = [shamlet| <h1>Hello
<p>world
@luite
luite / ghcLoad.hs
Created June 12, 2013 11:58
load files quickly
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import Control.Applicative
import Control.Concurrent
import Control.Monad
import Data.Time.Clock
import Diagrams.Prelude
import Diagrams.Backend.Cairo
import System.Posix.Process