Skip to content

Instantly share code, notes, and snippets.

@sir-wabbit
sir-wabbit / sharppatcher.cs
Last active August 29, 2015 14:10
SharpPatcher example
class A {
[Patch(New = true)]
private int newField;
[Patch(AccessRights = true)]
public int privateField;
public int Method1(int x);
[Patch(Name = "Method1")]
public int Method1Patch(int x) {
public void Match(AssemblyDefinition first, AssemblyDefinition second)
{
Contract.Requires<ArgumentNullException>(first != null);
Contract.Requires<ArgumentNullException>(second != null);
if (first.Modules.Count > 1 || second.Modules.Count > 1)
throw new NotImplementedException("Assemblies with more than one module are not supported yet.");
Match(first.MainModule, second.MainModule);
}
{
"metadata": {
"name": "Untitled1"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from collections import namedtuple
PutStrLn = namedtuple('PutStrLn', 'value')
Read = namedtuple('Read', [])
def hello():
_ = yield PutStrLn('Hello.')
return True
def f(myname):
sealed trait Nat { type N <: Nat }
sealed trait S[P <: Nat] extends Nat { type N = S[P] }
sealed trait Z extends Nat { type N = Z }
sealed trait Pred[A <: Nat] { type Out <: Nat }
object Pred {
def apply[A <: Nat](implicit pred: Pred[A]): Aux[A, pred.Out] = pred
type Aux[A <: Nat, B <: Nat] = Pred[A] { type Out = B }
implicit def pred[B <: Nat]: Aux[S[B], B] = new Pred[S[B]] { type Out = B }
}
#!/usr/bin/env python
from struct import pack, unpack
import re
import os, errno
import os.path
def mkdir_p(path):
try:
os.makedirs(path)

Current MonadError

MonadError in cats has the following laws:

  • L1: handle(raise(e))(f) == f(e)
  • L2: pure(a) >>= (_ => raise(e)) == raise(e)
  • L3: raise(e) >>= (_ => point(a)) == raise(e)

And it is defined roughly like this:

trait MonadError[F[_], E] {
import cats.{MonadError, Monad}
import cats.data.Xor
import scala.annotation.tailrec
object io {
object unsafe {
type Val = Any with ({ type Tag = Any })
object Val {
def point:             ()                => F[Unit]
def pure[A]:           A                 => _       => F[A]
def raiseError[A]:     E                 => _       => F[A]
def zero[A]:           ()                => _       => F[A]
def map[A, B]:         (A => B)          => F[A]    => F[B]
def flatMap[A, B]:     (A => F[B])       => F[A]    => F[B]
def ap[A, B]:          (F[A => B])       => F[A]    => F[B]
def handleErrorWith:   (E => F[A])       => F[A]    => F[A]
def product[A, B]:     F[B]              => F[A]    => F[(A, B)]