Skip to content

Instantly share code, notes, and snippets.

@stew
stew / guid.hs
Last active November 15, 2021 18:29
type 4 uuids
unique type Guid = Guid Nat Nat Nat Nat
Guid.data1 = cases
Guid data1 _ _ _ -> data1
Guid.data2 = cases
Guid _ data2 _ _ -> data2
Guid.data3 = cases
Guid _ _ data3 _ -> data3
@stew
stew / Cargo.toml
Last active July 19, 2020 03:31 — forked from johnynek/Cargo.toml
a toy example of CSV wordcount.
[package]
name = "hello"
version = "0.1.0"
authors = ["P. Oscar Boykin <[email protected]>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
csv = "1.1"
# unbind some default keybindings
unbind C-b
# set prefix key to ctrl-a
set -g prefix C-o
# lower command delay
set -sg escape-time 1
# start first window and pane at 1, not zero
@stew
stew / shell.nix
Created February 27, 2019 07:13
shell.nix for rust project
with import <nixpkgs> {
overlays = map import [ ./nix/rust-overlay.nix ];
};
stdenv.mkDerivation rec {
name = "hatchway";
buildInputs = [
rustChannels.stable.rust
# rustChannels.nightly.rust
openssl
pkgconfig
@stew
stew / make-scala-project.el
Last active June 30, 2017 04:53
make-scala-project
(defun stew-write-file (fn str)
(with-temp-buffer
(insert str)
(write-region (point-min) (point-max) fn t)))
(defun stew-make-build.properties (fn)
(let ((build.properties (concat "sbt.version=" sbt-version "\n")))
(stew-write-file fn build.properties)))
(defun stew-make-plugins.sbt (fn)
object BTree {
type Children[A] = (Option[A], Option[A])
// We can define a non-empty binary tree as being a Cofree using the
// above pattern, with each node labelled by both a value, and
// memoized height of the tree.
type BTree[A] = Cofree[Children, (A,Int)]
@inline def extract[A](x: BTree[A]) = x.head._1
@inline def height[A](x: BTree[A]): Int = x.head._2
@stew
stew / adjunction.scala
Created November 22, 2016 19:18
don't know if I can make line 89 work
package adjunction
import cats._
/**
* An Adjunction is a relationship between two functors:
* - `F`, the "left-adjoint"
* - `G`, the "right-adjoint"
*
@stew
stew / adjunction.scala
Last active March 15, 2016 15:22
Play with adjunctions, specifically with composing Writer -| Reader
adjunction
import cats._
abstract class Adjunction[F[_], G[_]] { self =>
def left[A,B](a: A)(f: F[A] => B): G[B]
def right[A,B](fa: F[A])(f: A => G[B]): B
def unit[A](a: A): G[F[A]] =
package dogs
import Predef._
import dogs.Order.{GT, EQ, LT, Ordering}
import dogs.std.intOrder
import scala.annotation.tailrec
import scala.math
sealed abstract class BinaryTree[A] {
import BinaryTree._
@stew
stew / gist:245037c48848f80eb5ca
Created January 21, 2016 23:45
runTraverseRWST.scala
def runTraverseRWST[F[_], G[_], R, W: Monoid, S, A, B](fa: F[A])(f: A => RWST[G,R,W,S,B])(r: R, s: S)(implicit F: Traverse[F], G: Monad[G]): G[(W,F[B],S)] = {
F.traverse[({type λ[α]=RWST[G,R,W,S,α]})#λ,A,B](fa)(f)(RWST.rwstMonad[G,R,W,S]).run(r,s)
}