Skip to content

Instantly share code, notes, and snippets.

@sinelaw
sinelaw / test-search.hs
Last active December 12, 2015 03:09
Added dynamic programming with parallelization
{-# LANGUAGE NoMonomorphismRestriction #-}
module Main where
import Debug.Trace (traceShow)
import Data.List (minimumBy, sortBy, genericLength)
import Control.Monad ((=<<), liftM, liftM2)
import Data.Maybe (fromJust, isJust)
import System.IO (hPutStrLn, stderr)
import Control.Parallel (par, pseq)
{-# LANGUAGE NoMonomorphismRestriction #-}
module Main where
import Debug.Trace (traceShow)
import Data.List (minimumBy, sortBy, genericLength)
import Control.Monad ((=<<), liftM, liftM2)
import Data.Maybe (fromJust)
trace1 x = traceShow x x
/*jsl:option explicit*/
"use strict";
// /////////////////////////////////////////////////////////////////////
// // JQUERY EXTENSIONS
/* Removed this part.. */
/////////////////////////////////////////////////////////////////////
// STRING FORMATTING
@sinelaw
sinelaw / Parser.hs
Last active October 31, 2015 22:20
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE StandaloneDeriving #-}
-- |
module Main where
import Control.Applicative (Alternative(..), (<|>))
import Data.List (foldl', intercalate)
import Data.Monoid ((<>))
@sinelaw
sinelaw / optional-args.js
Last active September 9, 2015 20:50
optional args using polymorphic records + record field constraints
// foo :: { 0: Num, 1: Maybe Num } -> Num
function foo(a, opt_b) {
var b = opt_b == undefined ? 3 : opt_b;
return a + b;
}
// foo here inferred to have this type:
// RowFields r Maybe => { 0: Num | r } -> b
foo(3); // translated to: foo { 0 = 3 | .. }
@sinelaw
sinelaw / bla.hs
Created September 9, 2015 20:26
type case simulated using polymorphic sums
foo :: +{ Num : Number, Str : String | r } -> Number
function foo(x) {
if (typeof x == Number) { .. x is a number here! ...; return 0 }
else if (typeof x == String) { .. a string here ..; return 1 }
else { .. }
}
\case x of
Num n -> ... ; 0
Str s -> ... ; 1
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
-- |
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()