Skip to content

Instantly share code, notes, and snippets.

@Taneb
Taneb / Distributive.agda
Created March 18, 2024 14:57
Recursion Schemes from Comonads in Agda
{-# OPTIONS --safe --without-K #-}
module Categories.Comonad.Distributive where
open import Categories.Category
open import Categories.Category.Construction.F-Algebras
open import Categories.Comonad
open import Categories.Functor
open import Categories.Functor.Algebra
open import Categories.Functor.DistributiveLaw
@Taneb
Taneb / Vec.agda
Created November 26, 2022 09:22
Proof that Vec is a monoidal bifunctor from Sets with disjoint union and Natop with addition to Sets with cartesian product
{-# OPTIONS --safe --without-K #-}
module Categories.Functor.Example.Vec where
open import Categories.Category.Core using (Category)
open import Categories.Category.Cartesian.Bundle using (CartesianCategory)
open import Categories.Category.Cartesian.Monoidal using (module CartesianMonoidal)
open import Categories.Category.Instance.Nat
open import Categories.Category.Instance.Sets
open import Categories.Category.Monoidal.Construction.Product using (Product-Monoidal)
@Taneb
Taneb / duals.scad
Last active October 25, 2022 17:30
Duals of polyhedra in OpenSCAD
// the golden ratio
phi = (sqrt(5) + 1) / 2;
// the points of a regular dodecahedron, oriented "somehow"
dodecahedron_points =
[ [ 1 , 1 , 1 ] // 0
, [ 1 , 1 , -1 ]
, [ 1 , -1 , 1 ]
, [ 1 , -1 , -1 ]
, [ -1 , 1 , 1 ] // 4
@Taneb
Taneb / LogicT.hs
Created August 3, 2021 11:11
Deriving LogicT from Codensity
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE UndecidableInstances #-}
module LogicT where
import Control.Applicative
import Control.Monad
import Data.Monoid
@Taneb
Taneb / ReadOnly.hs
Created July 21, 2021 09:42
Make a servant server read only by throwing 403 errors for anything that isn't a GET
class ReadOnly api where
readOnly :: Proxy api -> ServerT api Handler -> ServerT api Handler
instance (ReadOnly a, ReadOnly b) => ReadOnly (a :<|> b) where
readOnly (Proxy :: Proxy (a :<|> b)) (a :<|> b) = (readOnly (Proxy :: Proxy a) a :<|> readOnly (Proxy :: Proxy b) b)
instance (ReadOnly api) => ReadOnly (Description desc :> api) where
readOnly (Proxy :: Proxy (Description desc :> api)) api = readOnly (Proxy :: Proxy api) api
instance (ReadOnly api) => ReadOnly ((path :: Symbol) :> api) where
module Regex where
import Control.Applicative
import Data.Profunctor
data Regex c a = Regex (Maybe a) (c -> Regex c a)
instance Functor (Regex c) where
fmap f (Regex xm xr) = Regex (fmap f xm) (fmap f . xr)
@Taneb
Taneb / yes.agda
Created September 7, 2020 13:52
Yes in Agda
module Yes where
open import Codata.Musical.Notation
open import Data.List using (List; []; _∷_)
open import Data.String using (String; unwords; _++_)
open import Data.Unit using (⊤)
open import Function using (case_of_)
{-# LANGUAGE DataKinds #-}
module GenerateStatus where
import qualified Network.HTTP.Types.Status as Status
import GHC.TypeNats
class KnownNat n => KnownStatus n where
statusVal :: proxy n -> Status.Status
instance KnownStatus 100 where
@Taneb
Taneb / agda.nix
Created March 24, 2020 21:58
Agda overlay
pkgself: pkgsuper:
{
haskell = pkgsuper.haskell // {
packageOverrides = self: super: {
Agda = pkgself.haskell.lib.doJailbreak super.Agda;
time-compat = pkgself.haskell.lib.doJailbreak super.time-compat;
};
};
}
open import Level
module Categories.Category.Closed.Instance.Sets (o : Level) where
open import Categories.Category
open import Categories.Category.Instance.Sets
open import Categories.Category.Closed (Sets o)
open import Axiom.Extensionality.Propositional
open import Data.Product