Skip to content

Instantly share code, notes, and snippets.

@mietek
mietek / Main.agda
Created July 30, 2017 01:59 — forked from puffnfresh/Main.agda
cat in Agda
module Main where
import IO.Primitive as Prim
open import Coinduction
open import Data.Unit
open import IO
cat : IO ⊤
cat = ♯ getContents >>= (\cs → ♯ (putStr∞ cs))
@mietek
mietek / Brouwer.agda
Last active June 24, 2017 11:38
“Theorem. Absurdity of absurdity of absurdity is equivalent to absurdity.”
module Brouwer where
-- From Brouwer’s Cambridge lectures on intuitionism (1946-1951):
--
-- “Theorem. Absurdity of absurdity of absurdity is equivalent to absurdity.
--
-- Proof. Firstly, since implication of the assertion y by the assertion x implies
-- implication of absurdity of x by absurdity of y, the implication of absurdity of
-- absurdity by truth (which is an established fact) implies the implication of
module DecidableOPE where
open import Agda.Primitive using (_⊔_)
data ⊥ : Set where
elim⊥ : ∀ {ℓ} {X : Set ℓ} → ⊥ → X
elim⊥ ()
infix 3 ¬_
@mietek
mietek / Prelude.agda
Last active May 27, 2017 15:50
How to overload Agda integral literals as typed de Bruijn indices
module Prelude where
open import Agda.Primitive public
using (_⊔_ ; lsuc)
-- Truth.
open import Agda.Builtin.Unit public
using (⊤)
module Main where
main :: IO ()
main = do
str <- getLine
let x = show (read str)
putStrLn x
{-
$ ghc -Wall -o foo Main.hs
open import Data.Maybe using (Maybe ; just)
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl)
bad₁ : {A : Set} {x y : A} → (just x) ≡ (just y) → x ≡ y
bad₁ p = {!!}
bad₂ : ∀ {a} {A : Set a} {x y : A} → (just x) ≡ (just y) → x ≡ y
bad₂ p = {!!}
good₁ : {A : Set} {x y : A} → (Maybe.just x) ≡ (Maybe.just y) → x ≡ y
module DataCodata where
open import Data.Product using (_×_ ; _,_)
open import Data.Sum using (_⊎_ ; inj₁ ; inj₂)
--------------------------------------------------------------------------------
case : ∀ {ℓ ℓ′ ℓ″} → {X : Set ℓ} {Y : Set ℓ′} {Z : Set ℓ″}
@mietek
mietek / Church.agda
Last active November 30, 2016 23:05
module Church where
open import Agda.Primitive public using (_⊔_ ; lsuc)
record ⊤ : Set where
instance
constructor ∙
infixl 5 _,_
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
@mietek
mietek / Sym1.hs
Last active November 13, 2016 02:14
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Rank2Types #-}
import Data.String (IsString, fromString)
import GHC.TypeLits (KnownSymbol, Symbol, someSymbolVal, symbolVal)