Skip to content

Instantly share code, notes, and snippets.

View AndrasKovacs's full-sized avatar

András Kovács AndrasKovacs

View GitHub Profile
@AndrasKovacs
AndrasKovacs / ReverseTraversable.hs
Last active August 13, 2018 15:13
Total reversing for Traversable
{-# language
TypeInType, ScopedTypeVariables, RankNTypes,
GADTs, TypeOperators, TypeApplications, BangPatterns
#-}
-- requires ghc-typelits-natnormalise
{-# options_ghc -fplugin GHC.TypeLits.Normalise #-}
{-|
Tested with ghc-8.4.3
data Ty : Set where
ι : Ty
_⇒_ : Ty → Ty → Ty
infixr 3 _⇒_
data Con : Set where
∙ : Con
_▶_ : Con → Ty → Con
infixl 3 _▶_
@AndrasKovacs
AndrasKovacs / MinimalDepTC.hs
Created June 9, 2018 11:28
Minimal bidirectional dependent type checker with type-in-type. Related to Coquand's algorithm.
{-# language OverloadedStrings, UnicodeSyntax, LambdaCase,
ViewPatterns, NoMonomorphismRestriction #-}
{-# options_ghc -fwarn-incomplete-patterns #-}
{- Minimal bidirectional dependent type checker with type-in-type. Related to Coquand's
algorithm. #-}
import Prelude hiding (all)
@AndrasKovacs
AndrasKovacs / TypeLambdasNoSingletons.hs
Created May 13, 2018 18:38
Type lambdas without singletons dependency
{-# language ScopedTypeVariables, RankNTypes, TypeFamilies,
UndecidableInstances, GADTs, TypeOperators,
TypeApplications, AllowAmbiguousTypes, TypeInType,
StandaloneDeriving #-}
import Data.Kind
-- singletons
--------------------------------------------------------------------------------
@AndrasKovacs
AndrasKovacs / TypeLambdas.hs
Last active September 23, 2019 14:48
Type lambdas and induction with GHC 8.4.2 and singletons
{-# language TemplateHaskell, ScopedTypeVariables, RankNTypes,
TypeFamilies, UndecidableInstances, DeriveFunctor, GADTs,
TypeOperators, TypeApplications, AllowAmbiguousTypes,
TypeInType, StandaloneDeriving #-}
import Data.Singletons.TH -- singletons 2.4.1
import Data.Kind
-- some standard stuff for later examples' sake
@AndrasKovacs
AndrasKovacs / STLCSubst.agda
Last active March 2, 2025 02:50
Example of complete STLC substitution calculus
{-# OPTIONS --without-K #-}
{-
Below is an example of proving *everything* about the substitution calculus of a
simple TT with Bool.
The more challenging solution:
- If substitutions are defined as lists of terms, then if you manage to
prove that substitutions form a category, almost certainly you're done,
since you can only prove this is you have all relevant lemmas.
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
import Data.Kind
import Data.Coerce
-- type synonyms
--------------------------------------------------------------------------------
@AndrasKovacs
AndrasKovacs / ST.agda
Last active May 7, 2022 11:31
Computing ST monad in vanilla Agda
open import Algebra
open import Data.Bool
open import Data.Empty
open import Data.List
open import Data.List.Properties
open import Data.Nat
open import Data.Product
open import Data.Unit
open import Function
@AndrasKovacs
AndrasKovacs / EffInference.hs
Last active May 14, 2018 09:50
Enhanced type inference for extensible effects with (limited) type reflection
{-# language
RankNTypes, GADTs, TypeInType, LambdaCase, TypeApplications,
TypeOperators, StandaloneDeriving, TupleSections, EmptyCase,
ScopedTypeVariables, TypeFamilies, ConstraintKinds,
FlexibleContexts, MultiParamTypeClasses, AllowAmbiguousTypes,
FlexibleInstances, DeriveFunctor, UndecidableInstances,
NoMonomorphismRestriction #-}
module EffInference where
{-# OPTIONS --without-K #-}
open import Data.List
open import Data.Sum
open import Relation.Binary.PropositionalEquality
module _ (A : Set) where
data _∈_ (a : A) : List A → Set where
here : ∀ {as} → a ∈ (a ∷ as)