This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* formalization attached to my answer to https://cstheory.stackexchange.com/questions/53855/can-we-use-relational-parametricity-to-simplify-the-type-forall-a-a-to-a *) | |
From Coq Require Import Lia. | |
Definition U : Type := forall A : Type, ((A -> A) -> A) -> A. | |
(* Try enumerating solutions by hand. After the initial [intros], | |
we can either complete the term with [exact xi], | |
or continue deeper with [apply f; intros xi]. *) | |
Goal U. | |
Proof. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env cabal | |
{- cabal: | |
build-depends: base, effectful-core | |
-} | |
-- Usage: cabal run Coroutine.hs | |
{-# LANGUAGE | |
DataKinds, | |
FlexibleContexts, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* https://proofassistants.stackexchange.com/questions/3841/assistance-using-destruct-on-an-equality-proof-for-functors/3843 *) | |
(* Proof of associativity of functor composition without UIP *) | |
(* 1. Intuition: treat equality as a proper algebraic structure: | |
think of it as a category (aka. the discrete category), not an equivalence relation. *) | |
(* 1a. An equality between morphisms, f = g, becomes the existence of a morphism between f and g. *) | |
(* 1b. In the definition of a category, homsets are thus categories. | |
The resulting structure is known as a 2-category. https://ncatlab.org/nlab/show/2-category | |
You can kepp applying the same generalization to the morphism category, resulting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE BangPatterns #-} | |
import Criterion | |
import Criterion.Main | |
import Data.List (inits, scanl') | |
import Data.Primitive.Array | |
import GHC.Exts (RealWorld) | |
import System.IO.Unsafe | |
-- base implementation, using queues |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* A trick to print the simplified type of something *) | |
Definition type_of {A : Type} (a : A) : Type := A. | |
Arguments type_of _ /. | |
Notation simpl_type_of a := ltac:(let A := eval simpl in (type_of a) in exact A). | |
(* Example *) | |
Parameter p : forall x, 3 + x = x. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- counter.hs: count comments and lines of code in .lagda.md files. | |
Usage: | |
cat src/*.lagda.md|runghc counter.hs | |
Counting method: | |
Triple backticks either start or end a code block. | |
Triple backtick lines are not counted. | |
Code lines starting with `--` are counted as comments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Q: How to fix the last two commented lines? | |
-- | |
-- Summary: Two intrinsically typed calculi A and B, and a translation from A to B. | |
-- The translation consists of a translation on types, followed by a translation on terms | |
-- indexed by the translation on types. | |
-- Agda won't let me case-split in the translation of (term) variables. | |
-- | |
-- Signs of trouble: | |
-- - green slime in _A.∋_ and _B.∋_ | |
-- - with clauses (rather than only pattern-matching on arguments) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE RankNTypes, GADTs #-} | |
module O where | |
data Coyoneda g a where | |
Coyoneda :: forall g a x. g x -> (x -> a) -> Coyoneda g a | |
newtype Obj f g = Obj { unObj :: forall a. f a -> Coyoneda g (a, Obj f g) } | |
compose :: Obj f g -> Obj g h -> Obj f h | |
compose (Obj a) (Obj b) = Obj (\f -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From Coq Require Import List. | |
Import ListNotations. | |
Inductive bintree : Type := | |
| Leaf : bintree | |
| Node : bintree -> nat -> bintree -> bintree. | |
Inductive tree := | |
| TNode : nat -> list tree -> tree. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Freer (F : Set → Set) (A : Set) : Set₁ where | |
pure : A → Freer F A | |
bind : (B : Set) → F B → (B → Freer F A) → Freer F A | |
data Freest {A : Set} (J : A → Set) (F : A → Set) (a : A) : Set where | |
pure : J a → Freest J F a | |
bind : (b : A) → F b → (J b → Freest J F a) → Freest J F a | |
data R {A : Set} (J : A → Set) (F : A → Set) : Set → Set where | |
mkR : (a : A) → F a → R J F (J a) |