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 / plane-curves.rkt
Last active November 19, 2024 10:56
plane curves: lemniscate of Bernoulli, deltoid curve, astroid, and epitrochoid
#lang racket
(require plot)
(define (interval start end [step .01])
(stream->list (in-range start end step)))
(define (plot-para f int)
(plot (lines (map f int))))
(define (lemniscate-of-Bernoulli t)
(list (/ (cos t) (+ 1 (expt (sin t) 2)))
@dannypsnl
dannypsnl / space-curves.rkt
Created November 19, 2024 10:42
space curves: toroidal spiral, trefoil knot, and twisted cubic
#lang racket
(require plot)
(define (toroidal-spiral t)
(define n 10)
(list (* (+ 4 (sin (* n t))) (cos t))
(* (+ 4 (sin (* n t))) (sin t))
(cos (* n t))))
(plot3d
(lines3d (map toroidal-spiral
@dannypsnl
dannypsnl / integral.rkt
Created November 12, 2024 08:02
Compute numerical integration
#lang racket
(require plot)
(define (up x)
(sqrt (- 1 (sqr x))))
(define (down x) (- (up x)))
(plot (list (function up)
(function down))
#:x-min -1 #:x-max 1)
@dannypsnl
dannypsnl / cmd-parser.rkt
Created September 1, 2024 12:01
Write command line options parser & handler via algebraic effect style
#lang racket
(require racket/control
"with.rkt")
(define (consume str args)
(match args
[(cons head tail)
#:when (string=? str head)
(values tail #t)]
[_ (values args #f)]))
@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