Skip to content

Instantly share code, notes, and snippets.

View Blaisorblade's full-sized avatar

Paolo G. Giarrusso Blaisorblade

View GitHub Profile
@mietek
mietek / post-build-hook
Created February 9, 2015 00:49
Halcyon post-build hook validating sdist
#!/usr/bin/env bash
source "${HALCYON_DIR}/src.sh"
post_build_hook () {
local tag source_dir build_dir
expect_args tag source_dir build_dir -- "$@"
local label source_hash sdist_dir
@b-studios
b-studios / notes.scala
Last active August 29, 2015 14:16
Comparing Object Encodings
/**
* This file contains some notes taken while reading:
*
* Comparing Object Encodings
* Kim B. Bruce, Luca Cardelli and Benjamin C. Pierce
*/
package object encodings {
// Library Stuff
trait Fix[F[_]] {
@milessabin
milessabin / gist:65fa0d4ef373781d3ab4
Last active July 23, 2017 11:17
Empty refinements prevent unwanted widening when assigning singleton-typed values to a val.
// Used in shapeless here: https://github.com/milessabin/shapeless/blob/master/core/src/main/scala/shapeless/syntax/singletons.scala#L42
scala> def narrow[T <: AnyRef](t: T): t.type = t
narrow: [T <: AnyRef](t: T)t.type
scala> val s1 = narrow("foo") // Widened
s1: String = foo
scala> def narrow[T <: AnyRef](t: T): t.type {} = t // Note empty refinement
narrow: [T <: AnyRef](t: T)t.type
@viktorklang
viktorklang / Gistard.scala
Last active June 9, 2017 07:27
Gistard — an sbt autoplugin for depending on Gists — such as Gistard itself
/*
Copyright 2015 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@drblue
drblue / fix_onedrive.sh
Last active April 3, 2025 04:42
Fix OneDrive for Mac CPU usage
#!/bin/bash
## Fix OneDrive for Mac CPU usage
##
## Seems this is still a problem 5 years later after I created this little gist.
## I have long since stopped using OneDrive (luckily), but according to
## comments below, I have added the new path for OfficeFileCache for macOS
## Mojave (10.14) and Catalina (10.15).
## Run this on macOS Mojave (10.14) and Catalina (10.15)
find ~/Library/Containers/ -type d -name OfficeFileCache -exec rm -r {} +
@gallais
gallais / UntypedLambda.agda
Created September 7, 2015 18:53
Interpreting the untyped lambda calculus in Agda
{-# OPTIONS --copatterns #-}
module UntypedLambda where
open import Size
open import Function
mutual
data Delay (A : Set) (i : Size) : Set where
@etorreborre
etorreborre / lawvere.txt
Last active June 23, 2016 03:22
Lawvere theories and effects
The Category Theoretic Understanding of Universal Algebra: Lawvere Theories andMonads:
- http://www.pps.univ-paris-diderot.fr/~mellies/mpri/mpri-ens/articles/hyland-power-lawvere-theories-and-monads.pdf
- interesting for the historical part on how both concepts were developed
Just do it: simple monadic equational reasoning
- http://www.cs.ox.ac.uk/jeremy.gibbons/publications/mr.pdf
- laws for effects
Lawvere theories made a bit easier
- http://blog.sigfpe.com/2012/02/lawvere-theories-made-bit-easier.html
@paulp
paulp / oddity.txt
Created January 11, 2016 22:22
Whitespace Oddity
WHITESPACE ODDITY
by Paul Phillips, in eternal admiration of David Bowie, RIP
Bound Ctrl to Major mode
Bound Ctrl to Major mode
Read inputrc and set extdebug on
Bound Ctrl to Major mode (Ten, Nine, Eight, Seven, Six)
Connecting readline, options on (Five, Four, Three)
Check the syntax, may terminfo be with you (Two, One, Exec)
@gkossakowski
gkossakowski / asSeenFrom.md
Last active June 19, 2018 18:27
Understand Scala's core typechecking rules

Scala's "type T in class C as seen from a prefix type S" with examples

Introduction

Recently, I found myself in need to precisely understand Scala's core typechecking rules. I was particulary interested in understanding rules responsible for typechecking signatures of members defined in classes (and all types derived from them). Scala Language Specification (SLS) contains definition of the rules but lacks any examples. The definition of the rules uses mutual recursion and nested switch-like constructs that make it hard to follow. I've written down examples together with explanation how specific set of rules (grouped thematically) is applied. These notes helped me gain confidence that I fully understand Scala's core typechecking algorithm.

As Seen From

Let's quote the Scala spec for As Seen From (ASF) rules numbered for an easier reference:

Explaining Miles's Magic

Miles Sabin recently opened a pull request fixing the infamous SI-2712. First off, this is remarkable and, if merged, will make everyone's life enormously easier. This is a bug that a lot of people hit often without even realizing it, and they just assume that either they did something wrong or the compiler is broken in some weird way. It is especially common for users of scalaz or cats.

But that's not what I wanted to write about. What I want to write about is the exact semantics of Miles's fix, because it does impose some very specific assumptions about the way that type constructors work, and understanding those assumptions is the key to getting the most of it his fix.

For starters, here is the sort of thing that SI-2712 affects:

def foo[F[_], A](fa: F[A]): String = fa.toString