Skip to content

Instantly share code, notes, and snippets.

import Data.Attoparsec as A
import Data.Attoparsec.Binary as A
import Data.Attoparsec.Combinator as A
import Data.ByteString as B (pack, ByteString)
import Control.Concurrent.Async
import Control.Proxy as P
import Control.Proxy.TCP as P
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.12 (GNU/Linux)
mQENBEwjWc8BCACrUV/Axqjdq39BoBmGAzC4MlfltqZxvekF61n3V1WSpQDxUbPO
2Ljj59Nrqtqyzvl5uMslWgWeV2APVTai6aYZdNkxucTdW9UYn/pevJTiyYB67lcL
DzCkKrTMLBOcWmZznuQv4lvuZVAKs5M05GEOxprikYxT1fc4ks6pBkl2VfcCtHAB
I5sXEdLcaFy+n61vUjAjwveUDtlV8rc07T+0VI5a/O33maw+S5VHA+8EGIbUFNkS
Sj6DWs6XGL0nbBYeM71EyHmmi9o48VbE26ifZJTeDAOtS8agF6mB60cVEd9CpT5y
SVxnOAWXBUeXYf4KixrBT2ZY17BlcgmFcJj5ABEBAAG0MlJlbnpvIENhcmJvbmFy
YSA8cmVuem8uY2FyYm9uYXJhQGJpbmFyaWFncm91cC5jb20+iQE+BBMBAgAoAhsD
@k0001
k0001 / Main.hs
Last active August 29, 2015 14:07
{-# LANGUAGE JavaScriptFFI #-}
{- This code compiles and runs just fine -}
module Main where
import Control.Concurrent.MVar
import qualified Control.Exception as Ex
import GHCJS.Types
import GHCJS.Foreign
# nixos-rebuild test
building Nix...
building the system configuration...
these derivations will be built:
/nix/store/rp3nj1xr0i81hlajz5ld7fdwdvy9flxc-nixos-14.12.335.676e8d7.drv
building path(s) ‘/nix/store/gq44w0rr8m11lb595y5zdjnihk0bdzl4-nixos-14.12.335.676e8d7’
building /nix/store/gq44w0rr8m11lb595y5zdjnihk0bdzl4-nixos-14.12.335.676e8d7
cp: cannot stat '/etc/nixos/configuration.nix': No such file or directory
builder for ‘/nix/store/rp3nj1xr0i81hlajz5ld7fdwdvy9flxc-nixos-14.12.335.676e8d7.drv’ failed with exit code 1
error: build of ‘/nix/store/rp3nj1xr0i81hlajz5ld7fdwdvy9flxc-nixos-14.12.335.676e8d7.drv’ failed
@k0001
k0001 / hello.hs
Last active September 25, 2015 19:32
-- | Add a prefix and a suffix to a given monoid. Problem: which of the arguments is which?
surround :: (Monoid a) => a -> a -> a -> a
-- | Add a prefix and a suffix to a given monoid. No problem!
surround :: (Monoid a, prefix ~ a, suffix ~ a) => prefix -> suffix -> a -> a
asd=> CREATE TABLE foo (i int NOT NULL);
CREATE TABLE
asd=> INSERT INTO foo (i) VALUES (DEFAULT);
ERROR: null value in column "i" violates not-null constraint
DETAIL: Failing row contains (null).
-- | How do I write inductive instances for n-arity functions? Does this have a
-- name? How can I add functional dependencies to 'MapLast'?
class MapLast s t a b where
mapLast :: (a -> b) -> (s -> t)
instance MapLast a b a b where
mapLast = ($)
instance MapLast (z -> a) (z -> b) a b where
mapLast = (.)
instance MapLast (y -> z -> a) (y -> z -> b) a b where
mapLast = (.) . (.)
#! /usr/bin/env nix-shell
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/d2c451f967e344df14e63985963e57fb64a6c58d.tar.gz
#! nix-shell -i bash -p xz
# Outputs a xz tarball of all run-time and build-time dependencies
# of the given nix store paths that are provided as arguments.
function fexport()
{
set -x
nix-store --export $(nix-store -qR --include-outputs $(nix-store -qd "$@")) \
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
import Data.Kind
import GHC.Exts (Constraint)
import GHC.TypeLits (Nat)
type family StarMaker k :: Constraint where
StarMaker Type = ()
StarMaker (_ -> x) = StarMaker x
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeSynonymInstances #-}
import Data.Kind (Type)
import GHC.TypeLits (Nat)
class Starring ka
instance Starring Type