Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am philipnilsson on github.
  • I am philip_nilsson (https://keybase.io/philip_nilsson) on keybase.
  • I have a public key ASDHkjtDR2r-GC38Hf-Nfgu3rvC7nksXqOKS7_8EYji1swo

To claim this, I am signing this object:

import Control.Monad (void)
import Control.Applicative
import Data.Foldable (for_)
import Data.Monoid
import Text.Printf
data Attributed m w a = Attributed (m a) w
instance Functor m => Functor (Attributed m w) where
fmap f (Attributed m w) = Attributed (fmap f m) w
(setq-default line-spacing 4)
;; Supress initial scratch message
(setq initial-scratch-message nil)
(require 'package)
(add-to-list
'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)

Keybase proof

I hereby claim:

  • I am philipnilsson on github.
  • I am philip_nilsson (https://keybase.io/philip_nilsson) on keybase.
  • I have a public key ASDIhySUyBJvD-Ahd2EPn5ikDIUtBx35zxE7GnupBor34Ao

To claim this, I am signing this object:

-- Run a stateful computation and on completion
-- restore state to it's current value.
excursion st = do
oldState <- get
st
put oldState
// Some functional utilities
const map = f => arr => arr.map(f);
const id = x => x;
const concat = xs => [].concat(...xs);
const fold = (f, init) => xs => xs.reduce(f, init);
const sum = fold((x, y) => x + y, 0);
// Nested-list algebras
function alg(leaf, branch) {
return nested => nested instanceof Array
@philipnilsson
philipnilsson / gist:8378133
Last active February 25, 2016 23:54
Waterflow python
import functools
def scanl(f,x,it):
return functools.reduce(lambda xs, y: xs + [f(xs[-1],y)], it, [x])
def scanl1(f, it):
return scanl(f, it[0], it[1:])
def scanr1(f, it):
return reversed(scanl1(f, list(reversed(it))))
@philipnilsson
philipnilsson / gist:8375266
Last active January 2, 2016 23:19
Missing integer in arithmetic sequence
#include <stdio.h>
int main(void) {
int n, e, i = 0;
scanf("%d\n", &n);
scanf("%d", &e);
int sum = e, first = e, last = e, len = 1;
int delta;
while (++i < n) {
scanf(" %d", &e);
@philipnilsson
philipnilsson / gist:6998139
Created October 15, 2013 20:28
Use PosParser
-- | Experimental and very simple quasi-quotation of ECMAScript in
-- Haskell. Doesn't support anti-quotation as of now.
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE Rank2Types #-}
module Language.ECMAScript5.Syntax.QuasiQuote (js, jsexpr, jsstmt) where
import qualified Language.Haskell.TH as TH
import Language.Haskell.TH.Quote
@philipnilsson
philipnilsson / gist:6988512
Last active December 25, 2015 14:09
Language.ECMAScript5, unsafeCoerce to universally quantified constructor.
-- | Experimental and very simple quasi-quotation of ECMAScript in
-- Haskell. Doesn't support anti-quotation as of now.
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Language.ECMAScript5.Syntax.QuasiQuote (js, jsexpr, jsstmt) where
import qualified Language.Haskell.TH as TH
import Language.Haskell.TH.Quote
import Text.Parsec hiding (parse)