Each section should be run as the user or as root, pay attention to which one!
As $USER
curl https://nixos.org/nix/install | sh
with (import <nixpkgs> {}).pkgs; | |
with import <nixpkgs/pkgs/development/haskell-modules/lib.nix> { inherit pkgs; }; | |
let | |
QuickCheck = haskellPackages.QuickCheck_2_9_2; | |
quickcheck-io = haskellPackages.quickcheck-io.override { inherit QuickCheck; }; | |
quickcheck-instances = haskellPackages.quickcheck-instances.override { inherit QuickCheck; }; | |
hspec-meta = haskellPackages.hspec-meta.override { inherit QuickCheck quickcheck-io;}; | |
hspec-core = haskellPackages.hspec-core.override { inherit QuickCheck quickcheck-io hspec-meta;}; | |
hspec = haskellPackages.hspec.override { inherit QuickCheck hspec-core hspec-meta; }; | |
http-api-data = (doJailbreak haskellPackages.http-api-data_0_3_1).override {inherit QuickCheck hspec quickcheck-instances; }; |
{-# LANGUAGE TypeSynonymInstances #-} | |
import Data.Monoid | |
import Data.Maybe | |
-- How much water does a "histogram" hold? | |
-- | |
-- Inspired by Guy Steele's talk "Four Solutions to a Trivial Problem" | |
-- https://www.youtube.com/watch?v=ftcIcn8AmSY |
{-# LANGUAGE OverloadedStrings, BangPatterns #-} | |
module Main (main) where | |
import Criterion.Main | |
import Control.Applicative | |
import Data.Attoparsec.ByteString as P | |
import Data.Attoparsec.ByteString.Char8 (char8, endOfLine, isDigit_w8) | |
import Data.ByteString (ByteString) | |
import Data.Word (Word8) |
CREATE OR REPLACE FUNCTION table_update_notify() RETURNS trigger AS $$ | |
DECLARE | |
id bigint; | |
BEGIN | |
IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN | |
id = NEW.id; | |
ELSE | |
id = OLD.id; | |
END IF; | |
PERFORM pg_notify('table_update', json_build_object('table', TG_TABLE_NAME, 'id', id, 'type', TG_OP)::text); |
> import Control.Monad.Trans | |
> import Control.Monad.Trans.Iter | |
The completely iterative free monad transformer lets us capture non-termination as an effect. Furthermore, it's a monad *transformer*, so we can add non-termination on top of other effects. | |
A convenient combinator is | |
> untilSuccess :: Monad m => m (Maybe a) -> IterT m a | |
> untilSuccess f = maybe (delay (untilSuccess f)) return =<< lift f |
Various blog posts related to Nix and NixOS
configuration.nix
example.