Skip to content

Instantly share code, notes, and snippets.

View louisswarren's full-sized avatar

Louis Warren louisswarren

View GitHub Profile
@louisswarren
louisswarren / Qfasttail.hs
Last active April 10, 2019 23:41
Testing agda's optimisation
{-# LANGUAGE EmptyDataDecls, EmptyCase, ExistentialQuantification,
ScopedTypeVariables, NoMonomorphismRestriction, Rank2Types,
PatternSynonyms #-}
module MAlonzo.Code.Qfasttail where
import MAlonzo.RTE (coe, erased, AgdaAny, addInt, subInt, mulInt,
quotInt, remInt, geqInt, ltInt, eqInt, eqFloat, add64, sub64,
mul64, quot64, rem64, lt64, eq64, word64FromNat, word64ToNat)
import qualified MAlonzo.RTE
import qualified Data.Text
open import Agda.Builtin.Bool
data ⊥ : Set where
record ⊤ : Set where
isTrue : Bool → Set
isTrue true = ⊤
isTrue false = ⊥
data ℕ : Set where
@louisswarren
louisswarren / cast.py
Last active May 8, 2020 05:49
Cast using python type annotations
def cast(f):
returns = f.__annotations__['return']
if callable(returns):
casters = returns,
else:
casters = reversed(returns)
def inner(*args, **kwargs):
r = f(*args, **kwargs)
for caster in casters:
r = caster(r)
@louisswarren
louisswarren / returnlater.py
Last active January 30, 2019 02:50
Set the return value of a function, but return later
def returnlater(f):
def inner(*args, **kwargs):
x = f(*args, **kwargs)
r = None
while True:
try:
r = next(x)
except StopIteration as final:
if final.value is not None:
return final.value
@louisswarren
louisswarren / test.agda
Last active January 23, 2019 09:24
Testing of computation things
open import Agda.Builtin.Nat renaming (Nat to ℕ) hiding (_-_)
open import Agda.Builtin.List
open import Agda.Builtin.Equality
data ⊥ : Set where
infix 3 ¬_
¬_ : (A : Set) → Set
¬ A = A → ⊥
@louisswarren
louisswarren / Third.agda
Last active January 21, 2019 04:30
Closure, for the third time
open import Agda.Builtin.Sigma
open import Decidable
open import List
module Third (Ω : Set) (_≟_ : Decidable≡ Ω) where
data Filter {A : Set} (P : Pred A) : List A → List A → Set where
[] : Filter P [] []
_∷_ : ∀{x xs ys} → P x → Filter P xs ys → Filter P (x ∷ xs) (x ∷ ys)
@louisswarren
louisswarren / bug.agda
Last active January 16, 2019 09:52
Agda bug in 2.5.99.20181017-9
-- agda 2.5.99.20181017-9
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
data Fin : ℕ → Set where
@louisswarren
louisswarren / Baire.agda
Last active January 14, 2019 07:45
Pigeonhole principle
open import Agda.Builtin.Equality
open import Agda.Builtin.Nat renaming (Nat to ℕ)
open import Agda.Builtin.Sigma
data ⊥ : Set where
¬_ : Set → Set
¬ P = P → ⊥
Surjective : {A B : Set} → (A → B) → Set
@louisswarren
louisswarren / cantor.agda
Last active December 24, 2018 09:59
Cantor's diagonal argument (sort of)
open import Agda.Builtin.Equality
open import Agda.Builtin.Nat renaming (Nat to ℕ)
open import Agda.Builtin.Sigma
data ⊥ : Set where
¬_ : Set → Set
¬ P = P → ⊥
Surjective : {A B : Set} → (A → B) → Set
@louisswarren
louisswarren / bound.agda
Last active November 26, 2018 03:22
Some awful ugly testing of a bound function, as an idea of how to get fresh variables in tome
open import Agda.Builtin.Nat renaming (Nat to ℕ) hiding (_<_)
open import Agda.Builtin.Sigma
open import Decidable
open import List
prec : ∀ n m → suc n ≡ suc m → n ≡ m
prec n .n refl = refl
suc≢ : ∀ n → (suc n) ≢ n