Skip to content

Instantly share code, notes, and snippets.

View copumpkin's full-sized avatar
💭
Mostly unresponsive these days

Daniel Peebles copumpkin

💭
Mostly unresponsive these days
View GitHub Profile
@copumpkin
copumpkin / List.agda
Last active October 4, 2015 15:58
The List monad
module Categories.Agda.List where
open import Level
open import Categories.Category
open import Categories.Functor using (Functor; module Functor)
open import Categories.NaturalTransformation using (NaturalTransformation; module NaturalTransformation)
open import Categories.Adjunction
open import Categories.Monad
open import Categories.Agda
open import Categories.Support.PropositionalEquality
@copumpkin
copumpkin / Scratch.agda
Last active October 6, 2015 00:57
Fix
module Scratch where
open import Level
open import Function
open import Relation.Binary.PropositionalEquality
import Relation.Binary.EqReasoning as EqReasoning
-- Legend has it that parametricity is just dinaturality
module Parametricity {a} {F G : Set a → Set a → Set a}
(mapF : ∀ {A B C D} → (A → B) → (C → D) → F B C → F A D)
@copumpkin
copumpkin / gist:3115103
Created July 15, 2012 05:08
Unit is not ()
{-# LANGUAGE TypeFamilies, GADTs, EmptyDataDecls #-}
data Empty
data Unit = Unit
data Equal a b where
Refl :: Equal a a
type family F a :: *
@copumpkin
copumpkin / gist:4759099
Last active December 12, 2015 10:29
zipWith/foldr challenge!
-- This is the type we're working with.
data List a = List (forall r. (a -> r -> r) -> r -> r)
-- Implement this signature. It should not be inefficient, so if you're planning
-- on writing something like tail (notoriously inefficient using foldr) on our
-- List type, think again! It should be possible to write with the same time
-- complexity as the original. And of course, converting to/from a conventional
-- list is cheating :)
zipWith :: (a -> b -> c) -> List a -> List b -> List c
@copumpkin
copumpkin / Polymorphic.agda
Last active December 22, 2015 10:28
A strongly typed polymorphic lambda calculus
module Polymorphic where
import Level
open Level using (Level; _⊔_)
open import Function
open import Data.Product hiding (map)
open import Data.List hiding (all)
data Index {A : Set} : List A → A → Set where
zero : ∀ {τ Γ} → Index (τ ∷ Γ) τ
@copumpkin
copumpkin / Mutable.hs
Last active December 23, 2015 14:09
Mutable buffered Iteratee-like things. Goal is to let me reuse the input "chunks" but to prevent users from hanging onto them and seeing data they shouldn't see. Does it work? You can leak the MVector reference in an existential but then you can't do anything with it, right?
{-# LANGUAGE RankNTypes, BangPatterns #-}
module Mutable where
import Control.Monad
import Control.Monad.ST
import Data.STRef
import Data.Vector.Mutable (MVector)
import qualified Data.Vector.Mutable as MV
-- A read-only view into an MVector or similar
@copumpkin
copumpkin / Collatz.agda
Last active December 23, 2015 14:09
Here's Collatz, as promised. Hole left as exercise for the reader.
module Collatz where
open import Coinduction
open import Data.Nat hiding (_+_; _*_)
open import Data.Fin hiding (_+_; fromℕ; toℕ)
open import Data.Bin hiding (suc)
open import Data.Maybe
open import Data.Product
open import Data.List as List
open import Data.Colist
@copumpkin
copumpkin / UnboxableSums.hs
Last active December 24, 2015 19:19
Unboxable sigmas à la (unimplemented) Kmett, based on "unzipping" with a rank datastructure (currently super shitty). Please excuse the crap quality of the code, but I was just banging out ideas.
{-# LANGUAGE TypeFamilies, GADTs, ConstraintKinds, RankNTypes, TypeOperators, ScopedTypeVariables, FlexibleInstances, FlexibleContexts, MultiParamTypeClasses #-}
module UnboxableSums where
import Prelude hiding (lookup)
import Data.Word
import Data.Bits
import Data.Maybe
import Data.Function
import Data.Constraint
import qualified Data.Vector as V
@copumpkin
copumpkin / WeirdIso.agda
Created March 10, 2014 01:53
What could this strange type be isomorphic to?
module WeirdIso where
open import Coinduction
open import Data.Nat
open import Data.Stream
open import Relation.Binary.PropositionalEquality
data Weird : Set where
A : (x : Weird) → Weird
B : (x : ∞ Weird) → Weird
@copumpkin
copumpkin / Lawvere.agda
Last active October 26, 2017 22:53
Lawvere's theorem
module Lawvere where
open import Function.Equality hiding (cong)
open import Function.Surjection
open import Data.Product
open import Relation.Binary.PropositionalEquality
lawvere : {A B : Set} (f : A ↠ (A → B)) (g : B → B) → ∃ λ x → x ≡ g x
lawvere {A} {B} f g = h a , subst (λ r → h a ≡ g r) (cong (λ f → f a) (from-to refl)) refl
where