Skip to content

Instantly share code, notes, and snippets.

View rybla's full-sized avatar

Henry Blanchette rybla

View GitHub Profile
@rybla
rybla / IntrinsicSimpleLambdaCalculus.purs
Created July 26, 2024 14:35
intrinsically-typed simply-typed lambda calculus in Purescript
module Languages.IntrinsicallyTypedLambdaCalculus where
import Prelude hiding (($), type (~>))
import Data.Symbol (class IsSymbol)
import Prim.Row (class Cons)
import Type.Proxy (Proxy(..))
-- =============================================================================
@rybla
rybla / polymorphic_records_and_variants.ts
Last active July 12, 2024 19:59
in typescript, polymorphic records and variants
/*
The idea of this implementation is that a row (`Row`) serves as the
specification of either:
- a record (`Record<T extends Row>`) which is an object that, for each of the
elements of the row, has a key-value mapping from the element's tag to the
element's domain
- a variant (`Variant<T extends Row>`) which is a union of the row elements.
*/
type Tuple = any[]
@rybla
rybla / MyExistsConstrained.purs
Last active April 24, 2025 14:57
Pattern for existential types with typeclass constraints
module Data.MyExistsConstrained where
import Prelude
import Unsafe.Coerce (unsafeCoerce)
-- Suppose you want to use an existentially-quantified type. You can use the
-- `exists` package, which defines `Exists` likes so:
foreign import data Exists :: (Type -> Type) -> Type
@rybla
rybla / chat1.md
Last active March 6, 2024 00:12
Aljc.chat.md

Based on Slrj.chat.md; inspired by a conversation with aljce

User

You are a knowledgeable programming languages assistant. You help the user analyze a new programming language.

Aljc is a new programming language. The grammar of Aljc expressions is defined as follows, where x is any Aljc expression and A, B, and C are atomic values.

x ::= A | B | C | (x x)

(based on a conversation I had with Jacob Prinz)

SYSTEM

You are a knowledgeable programming languages assistant. You help the user analyze a new programming language.

USER

Slrj is a new programming language. The grammar of Slrj expressions is defined as follows, where "x" is any Slrj expression, and "A", "B", and "C" are atomic values.

@rybla
rybla / GenericPath.purs
Created December 19, 2022 19:11
Generic Paths in Purescript
--------------------------------------------------------------------------------
-- Tree
--------------------------------------------------------------------------------
data Tree a
= Tree a (Array (Tree a))
instance functorTree :: Functor Tree where
map f (Tree a ts) = Tree (f a) (map f <$> ts)
instance applyTree :: Apply Tree where
@rybla
rybla / Transpose.agda
Last active August 4, 2022 21:30
transpose and identity of vector-matrices in Agda
open import Data.Nat
data Vec : ℕ → Set → Set where
nil : ∀ {A} → Vec 0 A
cons : ∀ {A n} → A → Vec n A → Vec (suc n) A
record Traversable (F : Set → Set) : Set1 where
field
traverse : ∀ {S T : Set} {G : Set → Set} → (S → G T) → F S → G (F T)
{-# LANGUAGE GADTs, KindSignatures, DataKinds, RankNTypes, TypeFamilies, TypeFamilyDependencies, AllowAmbiguousTypes, ScopedTypeVariables #-}
module OverloadSingletonI where
import Prelude hiding (negate)
data OverloadMode = NegateInt | NegateBool
data SOverloadMode :: OverloadMode -> * -> * where
SNegateInt :: SOverloadMode NegateInt (Int -> Int)
@rybla
rybla / Inductive.agda
Last active September 18, 2021 02:17
module Inductive where
open import Data.Empty
open import Data.Unit
open import Data.Nat
open import Data.Fin using (Fin; zero; suc)
open import Data.Product
open import Data.Sum
module Inductive
@rybla
rybla / InaccessiblePattern.hs
Last active February 9, 2021 19:16
Liquid Haskell can't recognize the inaccessible pattern, where bound names are forced to be equal via types.
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module InaccessiblePattern where