Skip to content

Instantly share code, notes, and snippets.

View dalaing's full-sized avatar

Dave Laing dalaing

  • Brisbane, Australia
View GitHub Profile
diff --git a/compiler/typecheck/TcGenDeriv.lhs b/compiler/typecheck/TcGenDeriv.lhs
index 77bda82..1347f14 100644
--- a/compiler/typecheck/TcGenDeriv.lhs
+++ b/compiler/typecheck/TcGenDeriv.lhs
@@ -171,7 +171,7 @@ gen_Eq_binds loc tycon
fall_through_eqn
| no_tag_match_cons -- All constructors have arguments
= case pat_match_cons of
- [] -> [] -- No constructors; no fall-though case
+ [] -> [([], undefined_Expr)] -- No constructors; no fall-though case
@dalaing
dalaing / gist:9518669
Created March 12, 2014 23:15
There and back again
import Data.Profunctor
import qualified Data.Set as S
import Control.Monad.Trans (liftIO)
import Control.Monad.Trans.State
type MyMonad r = StateT (S.Set Int) IO r
runMyMonad :: MyMonad r -> IO r
runMyMonad m = evalStateT m S.empty
@dalaing
dalaing / gist:6e0744987098b261286e
Created November 11, 2015 03:40
Free for expressions
import Control.Monad.Free
data ExprF a k = Lit a | Add k k
instance Functor (ExprF a) where
fmap f (Lit x) = Lit x
fmap f (Add x y) = Add (f x) (f y)
type Expr a = Free (ExprF a) ()
module Queue (
empty
, isEmpty
, peek
, remove
, add
) where
data Queue a = Queue [a] [a] [a]
deriving (Eq, Show)
@dalaing
dalaing / language-input-shell.nix
Created July 31, 2016 03:32
Multi-project nix files
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default" }:
let
inherit (nixpkgs) pkgs;
haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};
@dalaing
dalaing / interesting.pl
Last active August 17, 2016 07:44
A fun Prolog snippet
% select(X,HasXs,OneLessXs) deletes a single X from HasXs
select(X, [X|Xs], Xs).
select(X, [Y|Ys], [Y|Zs]) <- select(X, Ys, Zs).
% insert(X,OneLessXs, HasXs) inserts X into OneLessXs at a non-deterministic position
insert(X, Ys, Zs) <- select(X, Zs, Ys).
% permutation1(Input, Output)
% non-deterministically select the head of the output, permute the remaining input and use as the tail
permutation1(Xs, [Z|Zs]) <- select(Z,Xs,Ys), permutation(Ys,Zs).
@dalaing
dalaing / gist:c4c48aeff051d2049e4bd1a5be05797d
Last active August 28, 2016 03:05
reactive-banana airlock
-- Things from reactive-banana in use:
-- - stepper
-- to accumulate state in a behavior from an inital value and the firings of an event
-- - <@> and <@
-- to sample behaviors at the point when an event occurs (with or without the value in the event)
-- - whenE
-- to filter events based on a Behavior Bool
-- - reactimate
-- to do IO when an event occurs
-- plus leftmost
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
module Run (
runner
) where
import Control.Monad.Reader (ReaderT, runReaderT)
import Data.Foldable (traverse_)
@dalaing
dalaing / Scratch.hs
Created October 13, 2017 06:30
Terria
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE FlexibleContexts #-}
module Scratch where
import Data.Monoid ((<>))
import Control.Monad.Trans (liftIO)
import Reflex.Dom.Core
{ config, pkgs, ...}: {
services.postfix = {
enable = true;
setSendmail = true;
};
services.postgresql = {
enable = true;
package = pkgs.postgresql;