Skip to content

Instantly share code, notes, and snippets.

-- |
module Bidirectional where
@sinelaw
sinelaw / gc.hs
Last active August 29, 2015 14:26
{-# LANGUAGE MagicHash #-}
module Main where
import Control.Monad
import Data.Word (Word64)
import qualified Data.ByteString.Char8 as BS8
import Control.DeepSeq
import qualified Data.Text.Array as A
import GHC.Prim
import GHC.Base (Int(..))
@sinelaw
sinelaw / superlamda.py
Last active August 29, 2015 14:23
Next-generation IDE for functional programming
# Next-generation IDE for functional programming
# Run it, and press any key to start writing code.
# It will automatically exit when you're done writing your function.
# Work in progress, currently supports factorial
import sys
factorial = 'fac n = if n > 1 then n * (fac (n - 1)) else 1'.split()
@sinelaw
sinelaw / ordArray.js
Last active August 29, 2015 14:22
ordArray generated function from GHCJS
var ordArray = function (__dict_Ord_9) {
return {
"__superclasses": {
"Prelude.Eq_0": function (_) {
return eqArray(__dict_Ord_9["__superclasses"]["Prelude.Eq_0"]({}));
}
},
compare: function (_20) {
return function (_21) {
if (_20.length === 0) {
@sinelaw
sinelaw / OptionalArg.hs
Last active August 29, 2015 14:19
OptionalArguments from ML in Haskell - see http://mlton.org/OptionalArguments
-- see http://mlton.org/OptionalArguments
module OptionalArg where
data Product a b = a :& b deriving Show
end (a, f) = f a
fold (a, f) g = g (a, f)
step0 h (a, f) = fold (h a, f)
step1 h (a, f) b = fold (h (b, a), f)
@sinelaw
sinelaw / ping.sh
Created April 8, 2015 12:02
parallel ping
cat hosts | xargs -P 0 -n1 -ihost bash -c 'ping -q -W 1 -c 1 host &> /dev/null || echo host failed'
@sinelaw
sinelaw / tailor.sh
Last active January 2, 2016 04:06
In-place tail: prints the last output line of a command, overriding it in-place
#!/bin/bash -eu
LOG_FILE=$1
SB="stdbuf -i0 -oL"
shift
tput sc
$@ 2>&1 | $SB tee $LOG_FILE | $SB cut -c-$(tput cols) | $SB sed -u 's/\(.\)/\\\1/g' | $SB xargs -0 -d'\n' -iyosi -n1 bash -c 'tput rc;tput el; printf "\r%s" yosi'
EXIT_CODE=${PIPESTATUS[0]}
tput rc;tput el;printf "\r" # Delete the last printed line
exit $EXIT_CODE
@sinelaw
sinelaw / indexable.hs
Created February 25, 2015 00:31
Associated types without type families - why can't this work?
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
class Indexable a where
instance Indexable (String, Int, Char) where
instance Indexable ([(String, a)], String, a) where
test1 :: Indexable (a,b,c) => a -> b -> c
{-# OPTIONS -Wall #-}
{-# LANGUAGE TypeFamilies, FlexibleInstances #-}
import Data.Map
class Indexable a where
type Index a
type Result a
index :: a -> Index a -> Result a
;;(load "/local-home/user18/repos/thirdparty/emacs-haskell-config/init.el")
(add-to-list 'load-path "~/repos/thirdparty/emacs-haskell-config/packages/haskell-mode/")
(require 'haskell-mode-autoloads)
(add-to-list 'Info-default-directory-list "~/repos/thirdparty/emacs-haskell-config/packages/haskell-mode/")
(require 'cl)
(add-to-list 'load-path "~/.emacs.d/lisp")
(require 'cask "~/.cask/cask.el")