Skip to content

Instantly share code, notes, and snippets.

-- Exercise: prove Peirce’s law <=> law of excluded middle in Haskell
{-# LANGUAGE Rank2Types #-}
module PeirceLEM where
import Data.Void
type Not a = a -> Void
type Peirce = forall a b. ((a -> b) -> a) -> a
@Rufflewind
Rufflewind / obfuscated-python
Last active August 29, 2015 14:20
some obfuscated Python script I wrote 7 years ago
0
o\
=0\
-+-0
d='''
KAkAAA
BzCwAAA
E1BU1RFU
k1JTkQKcx
EAAABFbnRl

Keybase proof

I hereby claim:

  • I am rufflewind on github.
  • I am rufflewind (https://keybase.io/rufflewind) on keybase.
  • I have a public key whose fingerprint is 760E 9C79 FB40 607A 1F52 AE49 0346 7153 8EB1 6548

To claim this, I am signing this object:

Improved GHC diagnostics

Analysis of Clang, GCC, and Rust

First let's analyze Clang, GCC, and Rust and see what we can learn from them.

Diagnostic entries

Diagnostics contain entries of this format (Rust calls them "spans"):

Poset fixity declarations

Syntax

infix order p, q where
  tighter than a, b
  associate left c, d
  looser than e, f

First-class type class instances

Type classes are rather fragile: it's really hard to make changes to a type class once because it can often break code downstream.

Type classes are in a sense like implicit parameters, with the additional constraint of coherency. If we think of them as such, then defining an instance such as

instance Monad Maybe where
 (&gt;&gt;=) = 
@Rufflewind
Rufflewind / sphtrace.hs
Last active October 15, 2015 05:29 — forked from wolfiestyle/sphtrace.hs
raytracer in haskell
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C
data Vec a = Vec { vecx, vecy, vecz :: !a }
instance Functor Vec where
fmap f (Vec x y z) = Vec (f x) (f y) (f z)
instance Applicative Vec where
pure x = Vec x x x
TIMEUNIT_MICROSECOND = 0
TIMEUNIT_SECOND = 1
TIMEUNIT_MINUTE = 2
TIMEUNIT_HOUR = 3
TIMEUNIT_DAY = 4
TIMEUNIT_MONTH = 5
TIMEUNIT_YEAR = 6
def round_datetime(timeunit):
'''Round the given time downward to some unit of time. For example:
@Rufflewind
Rufflewind / versioning-policy.md
Last active July 3, 2016 03:33
Versioning policy

Versioning policy

Some of my projects have 3-component version numbers. Others have 4-component version numbers. Be aware that the meaning of these two kinds of version numbers differ.

3-component version numbers

0.0.0

| | |

// stat.c
//
// TO RUN: cc -Wall stat.c && ./a.out
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>