Skip to content

Instantly share code, notes, and snippets.

View dorchard's full-sized avatar

Dominic Orchard dorchard

View GitHub Profile
@dorchard
dorchard / tutorial.py
Last active March 20, 2024 07:41
Code from NERC 2024 workshop live demos on 'Using types to rule out bugs: Python perspective'
from typing import TYPE_CHECKING
flag : bool = True
def greet(name: str) -> None:
"""Say hello to everyone"""
print("Hi " + name)
return None
greet("Manchester")
@dorchard
dorchard / fsqrt.hs
Last active February 7, 2024 17:08
Fast inverse square root in Haskell - Two ways
import Data.Bits
import Data.Word
import Foreign ( Ptr, new, castPtr, Storable(peek, poke) )
import System.IO.Unsafe
import Unsafe.Coerce
qsqrt :: Float -> Float
qsqrt x = 1 / qRsqrt x
qsqrt' :: Float -> Float
@dorchard
dorchard / ind.tex
Last active February 6, 2024 16:26
Syntax, operational semantics, and typing for indexed natural numbers
\documentclass[10pt]{article}
\usepackage{amssymb} %maths
\usepackage{amsmath} %maths
\usepackage[utf8]{inputenc} %useful to type directly diacritic characters
\usepackage[margin=4cm]{geometry}
\title{Indexed natural numbers}
\author{Dominic Orchard}
\begin{document}
@dorchard
dorchard / example.f90
Last active June 1, 2023 18:06
Fortran, function overloading on arity
program example
use naryfunc
implicit none
! Outputs 2 6 24
write(*,*) mult(2), mult(2, 3), mult(2, 3, 4)
end program example
module Flexible where
-- Exploring flexible graded monads, based on the work of Katsumata, McDermott, Uustalu and Wu
-- https://dylanm.org/drafts/flexibly-graded-presentations.pdf
open import Function
_⇒_ : {E : Set} -> (E -> Set) -> (E -> Set) -> Set
_⇒_ {E} X Y = forall (e : E) -> X e -> Y e
@dorchard
dorchard / examples.gr
Created January 13, 2022 10:29
Examples from the paper 'Linearity and Uniqueness: An Entente Cordiale'
-- # Examples from the paper 'Linearity and Uniqueness: An Entente Cordiale'
-- ## Linearity (see Section 2, Key ideas)
-- Linearity (with cake)
data Cake = Cake
data Happy = Happy
eat : Cake -> Happy
@dorchard
dorchard / scrub.hs
Last active September 17, 2021 10:57
Scrub e-mail addresses from HTML page
module Main where
import System.Environment (getArgs)
import System.Exit (exitFailure)
import Data.List (intercalate)
-- Scrub automata
scrub :: String -> [String]
scrub [] = []
scrub ('m':'a':'i':'l':'t':'o':':':rest) =
@dorchard
dorchard / Empty.agda
Created July 23, 2021 16:13
Some facts about empty types
module Empty where
open import Data.Empty
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Function.Inverse
-- Empty type has only unequal elements
uneq : (x y : ⊥) -> x ≢ y
uneq () y prf
@dorchard
dorchard / esop-2021-notes.md
Last active April 1, 2021 14:20
ESOP 2021 notes

My (partial and personal) notes from ESOP 2021.

Disclaimer: There may well be errors and omissions here, so please do read the original papers instead of relying on my notes! Apologies to the author's for any misrepresentation. Due to other pressures I am not able to take notes on all the talks, and some notes are partial.

Session 1 - Probabilistic Programming and Verification (Chaired by Sam Staton)

Automated Termination Analysis of Polynomial Probabilistic Programs - Marcel Moosbrugger et al.

@dorchard
dorchard / happy-birthday-hanne-and-flemming.rb
Last active February 17, 2021 17:01
Sonic Pi Happy Birthday for Nielsons' Festschrift 2016
# Sonic Pi code used in the intro of my talk on
# "Effect Systems Revisited — Control-Flow Algebra and Semantics" (Mycroft, Orchard, Petricek)
# https://kar.kent.ac.uk/61623/1/effects-revisited.pdf
# for Hanne and Flemming Nielson's Festschrift, January 2016.
# Not the prettiest or most modern SonicPi code!
use_transpose(6)
use_bpm(146)
use_synth :piano