Skip to content

Instantly share code, notes, and snippets.

@chris-martin
chris-martin / build.gradle
Created July 31, 2015 09:59
Method for launching a Scala REPL for a Gradle project.
task classpath << { println sourceSets.main.runtimeClasspath.asPath }
{-# language FlexibleContexts, FlexibleInstances, FunctionalDependencies #-}
module Idea where
class ComposeApply a b c | a b -> c where
(#) :: a -> b -> c
instance ComposeApply (a -> b) a b where
f # x = f x
data InfiniteList a = InfiniteList a (InfiniteList a)
traverseForever :: Applicative m => (a -> m b) -> InfiniteList a -> m c
traverseForever f (InfiniteList x xs) = f x *> traverseForever f xs
countUpwardsFrom :: Integer -> InfiniteList Integer
countUpwardsFrom n = InfiniteList n (countUpwardsFrom (n + 1))
forForever :: Applicative m => InfiniteList a -> (a -> m b) -> m c
forForever = flip traverseForever
{ coreutils, writeShellScript, lib, system, glibcLocales }:
rec {
inherit (builtins) derivation;
inherit (lib) concatMapStringsSep;
standardBuildInputs = [ coreutils ];
locale = { LC_ALL = "en_US.UTF-8"; LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive"; };
#! /usr/bin/env bash
set -eufo pipefail
nix-shell --pure --run 'ghcide --lsp'
import Control.Exception.Safe
import Control.Concurrent
bracketFork
:: IO resource
-- ^ The first action; will run in the current thread
-> (resource -> IO a)
-- ^ A final action that runs in the forked thread, with async exceptions masked
-> (resource -> IO b)
-- ^ Action that runs in the forked thread, with async exceptions unmasked
{
services.nginx = {
enable = true;
appendHttpConfig = ''
types {
text/html html;
text/css css;
text/xml xml rss;
image/gif gif;
@chris-martin
chris-martin / default.nix
Last active April 15, 2019 18:45
LaTeX + Nix setup for "Finding Success and Failure in Haskell"
{
pkgs =
import (import ./nixpkgs.nix) {};
texlive =
import ./texlive.nix { inherit (pkgs) texlive; };
fontsForLatex =
[
{ name = "google-fonts";
https://twitter.com/Cshearer41/status/1103717536921800704
Let a, b, c be the triangles, smallest to largest.
Observations from the illustration about the relative triangle sizes:
side b = 2 * height a [observation ab]
side c = 2 * height b [observation bc]
Let w be the rectangle's width and let h be its height.
{-# LANGUAGE LambdaCase #-}
import Prelude (Bool (True, False), Monad, (>>=))
ifThenElseM :: Monad m => m Bool -> m a -> m a -> m a
ifThenElseM cond ifTrue ifFalse =
cond >>= \case { True -> ifTrue; False -> ifFalse }
ifThenElseM' :: Monad m => [(m Bool, m a)] -> m a -> m a