Skip to content

Instantly share code, notes, and snippets.

open import Prelude
open import Builtin.Reflection
open import Tactic.Reflection.Quote
data TTerm {a} (A : Set a) : Set where
typed : Term → TTerm A
mkTyped : ∀ {a} {A : Set a} → A → Term → TTerm A
mkTyped _ t = typed t
@UlfNorell
UlfNorell / Search.agda
Created March 29, 2016 08:16
Fast search
module _ where
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Data.Nat hiding (_<_; _≤_) renaming (_<′_ to _<_; _≤′_ to _≤_)
open import Data.Nat.Properties
open import Data.Nat.Properties.Simple
open import Data.Product
open import Data.Empty
@UlfNorell
UlfNorell / LtReasoning.agda
Last active December 8, 2017 08:44
Equational reasoning with inequalities
-- In response to https://lists.chalmers.se/pipermail/agda/2017/009872.html
module _ where
open import Agda.Builtin.Equality
infix 0 case_of_
case_of_ : ∀ {a b} {A : Set a} {B : Set b} → A → (A → B) → B
case x of f = f x
-- Equality reasoning --
@UlfNorell
UlfNorell / Fulcrum.agda
Created April 27, 2018 11:04
Challenge 3 of the Great Theorem Prover Showdown
-- Problem 3 of @Hillelogram's Great Theorem Prover Showdown.
-- https://www.hillelwayne.com/post/theorem-prover-showdown
--
-- Implemented using current stable-2.5 branch of Agda
-- (https://github.com/agda/agda/tree/08664ac) and the agda-prelude
-- library (https://github.com/UlfNorell/agda-prelude/tree/d193a94).
module Fulcrum where
open import Prelude hiding (_≤?_)
@UlfNorell
UlfNorell / AscList.agda
Created August 30, 2018 07:41
Reversing an ascending list in Agda
-- Reversing an ascending list in Agda.
-- Challenge by @arntzenius: https://twitter.com/arntzenius/status/1034919539467677696
module AscList where
-- We'll go without libraries to make things clearer.
flip : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} → (A → B → C) → B → A → C
flip f x y = f y x
-- Step one is to define ordered lists. We'll roughly follow Conor McBride's approach
{-# OPTIONS --rewriting #-}
module _ where
open import Agda.Builtin.Bool
open import Agda.Builtin.Equality
open import Agda.Builtin.Unit
open import Agda.Builtin.String renaming (primStringEquality to _==_)
open import Agda.Builtin.List
@UlfNorell
UlfNorell / ToJSON.agda
Last active October 6, 2020 09:08
Working with type class functions in the Agda's Haskell FFI
open import Agda.Builtin.Nat
open import Agda.Builtin.List
open import Agda.Builtin.String
open import Agda.Builtin.IO
open import Agda.Builtin.Unit
{-# FOREIGN GHC
import Data.Text
import qualified Data.Text.IO as Text
@UlfNorell
UlfNorell / RecN-challenge.agda
Created June 13, 2022 11:32
Solution to @effectfully's RecN challenge
-- Challenge: https://github.com/effectfully/random-stuff/blob/master/RecN-challenge.agda
{-# OPTIONS --type-in-type #-} -- Just for convenience, not essential.
open import Function
open import Relation.Binary.PropositionalEquality
open import Data.Nat.Base
coerce : ∀ {A B} -> A ≡ B -> A -> B
coerce refl = id