Skip to content

Instantly share code, notes, and snippets.

View dannypsnl's full-sized avatar

Lîm Tsú-thuàn dannypsnl

View GitHub Profile
@dannypsnl
dannypsnl / tuple.agda
Created March 23, 2024 08:47 — forked from bobatkey/tuple.agda
"A Quick Introduction to Denotational Semantics using Agda" notes for talk given at TUPLE 2024 (https://typesig.comp-soc.com/tuple/)
{-# OPTIONS --postfix-projections #-}
module tuple where
------------------------------------------------------------------------------
--
{-# language
BlockArguments
, ImplicitParams
, LambdaCase
, OverloadedStrings
, PatternSynonyms
, Strict
, UnicodeSyntax
#-}
{-# options_ghc -Wincomplete-patterns -Wunused-imports #-}
@dannypsnl
dannypsnl / pcomb.ml
Created August 7, 2023 15:29 — forked from neel-krishnaswami/pcomb.ml
A linear-time parser combinator library in Ocaml
module C : sig
type t
val empty : t
val one : char -> t
val union : t -> t -> t
val inter : t -> t -> t
val top : t
val mem : char -> t -> bool
val make : (char -> bool) -> t
val equal : t -> t -> bool
@dannypsnl
dannypsnl / natmod.agda
Created July 19, 2023 06:33 — forked from Trebor-Huang/natmod.agda
Free natural model as an HIIT
{-# OPTIONS --cubical #-}
module natmod where
open import Cubical.Foundations.Prelude
data Ctx : Type
data _⊢_ : Ctx → Ctx → Type
data Ty : Ctx → Type
data Tm : Ctx → Type
-- This is halfway between EAT and GAT.
-- GAT is hard! Why is EAT so easy?
@dannypsnl
dannypsnl / BuildCFG.idr
Created December 29, 2022 11:55
build CFG for program
module Main
data Expr = E
data Stmt
= If Expr Stmt Stmt -- if (condition) then A else B
-- loop (condition):
-- do xxx
| Loop Expr Stmt
| SE String
@dannypsnl
dannypsnl / FindUnusedDefinitions.idr
Last active December 29, 2022 12:20
report unused definitions
module Main
import Control.App
import Control.App.Console
import Data.SortedSet
data Op = Add | Sub | Mul | Div
data Expr
= Var String
@dannypsnl
dannypsnl / Tyck.hs
Last active November 18, 2022 12:00
simple polymorphic type checker in haskell
{-# LANGUAGE LambdaCase #-}
module Tyck
( Term (..),
Type (..),
emptyContext,
emptySolution,
topInfer,
infer,
check,
@dannypsnl
dannypsnl / all-factors.rkt
Created October 9, 2022 20:06
all factors
#lang racket
(define prime-list '(2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59))
(define (factor-list n)
(define p-factor-list
(for/list ([p prime-list]
#:when (= (remainder n p) 0))
p))
(println p-factor-list)
@dannypsnl
dannypsnl / strictly-positive.rkt
Last active September 20, 2022 18:10
strictly positive checker
#lang racket
(require syntax/parse/define
(for-syntax syntax/stx))
(begin-for-syntax
(define-syntax-class type
#:datum-literals (->)
(pattern (~literal Type)
#:attr occurs (λ (D) #f))
(pattern x:id
@dannypsnl
dannypsnl / encasulate-future.rkt
Created September 15, 2022 10:20
use future in weird way
#lang racket/base
(require racket/future
racket/async-channel
racket/function
racket/match)
(define process-map (make-hasheq))
(struct pid ())
(struct process (id fu ch))