Skip to content

Instantly share code, notes, and snippets.

View dalaing's full-sized avatar

Dave Laing dalaing

  • Brisbane, Australia
View GitHub Profile
@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 / 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};
module Queue (
empty
, isEmpty
, peek
, remove
, add
) where
data Queue a = Queue [a] [a] [a]
deriving (Eq, Show)
@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) ()
@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
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