Skip to content

Instantly share code, notes, and snippets.

@kana-sama
kana-sama / Bin.hs
Created November 2, 2021 20:28
binary-v2
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
module Bin (BinarySegment (..), bin) where
import Control.Applicative ((<|>))
import Control.Monad (guard)
@ekmett
ekmett / ProxyT.hs
Created June 17, 2021 04:51
When functional dependencies don't
{-# Language FlexibleInstances #-}
{-# Language MultiParamTypeClasses #-}
{-# Language FlexibleContexts #-}
{-# Language UndecidableInstances #-}
{-# Language DeriveTraversable #-}
{-# Language NoStarIsType #-}
{-# Language StandaloneKindSignatures #-}
{-# Language RoleAnnotations #-}
-- | Dysfunctional dependencies
@gabriel-barrett
gabriel-barrett / qtt.md
Last active April 28, 2025 04:36
On quantity type theory

Basic QTT

Quantitative type theory (QTT) is an extension of dependent type theory which allows us to track the number of computational (non-erased) uses of variables in well-typed lambda terms. With such usage information, QTT allows us to combine dependent types with substructural types, such as linear, affine or relevant types.

While in a Martin-Löf style type theory typing judgments are of form x1 : A1, ..., xn : An ⊢ b : B, in QTT the bindings in the context

@johnchandlerburnham
johnchandlerburnham / ATaxonomyOfSelfTypes.md
Last active August 15, 2024 12:26
A Taxonomy of Self Types

A Taxonomy of Self-Types

Part I: Introduction to Self-Types

Datatypes in the Formality programming language are built out of an unusual structure: the self-type. Roughly speaking, a self-type is a type that can depend or be a proposition on it's own value. For instance, the consider the 2 constructor datatype Bool:

@ChrisPenner
ChrisPenner / Optics Cheatsheet.md
Last active April 21, 2025 12:45
Optics Cheatsheet
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module Main where
import GHC.OverloadedLabels
import GHC.Records
@AndrasKovacs
AndrasKovacs / IITfromNat.agda
Last active May 14, 2020 00:22
Constructing finitary inductive types from natural numbers
{-# OPTIONS --without-K #-}
{-
Claim: finitary inductive types are constructible from Π,Σ,Uᵢ,_≡_ and ℕ, without
quotients. Sketch in two parts.
1. First, construction of finitary inductive types from Π, Σ, Uᵢ, _≡_ and binary trees.
Here I only show this for really simple, single-sorted closed inductive types,
but it should work for indexed inductive types as well.
@i-am-tom
i-am-tom / FizzBuzz.hs
Last active December 21, 2024 10:17
Arguably the fastest implementation of FizzBuzz ever written.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UnsaturatedTypeFamilies #-}
import GHC.TypeLits
import Prelude hiding (Functor, Semigroup)
type Main = (Fizz <> Buzz) <$> (0 `To` 100)
@int-index
int-index / NamedDefaults.hs
Created April 23, 2018 12:38
named-defaults
{-# LANGUAGE KindSignatures, DataKinds, FlexibleInstances, FlexibleContexts,
FunctionalDependencies, TypeFamilies, TypeOperators,
PatternSynonyms, UndecidableInstances, ConstraintKinds,
TypeApplications, ScopedTypeVariables, CPP #-}
module NamedDefaults (FillDefaults, fillDefaults, (!.)) where
import Prelude (Maybe(..), id)
import Data.Kind (Type)
@Icelandjack
Icelandjack / ExtensibleIsomorphisms.markdown
Last active January 8, 2018 16:56
Encoding Overlapping, Extensible Isomorphisms