Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
(Come in under the shadow of this red rock)

Derrick Turk derrickturk

💭
(Come in under the shadow of this red rock)
View GitHub Profile
@derrickturk
derrickturk / bbencoding.dhall
Created Apr 17, 2021
Fun with Boehm-Berarduccin encoding, in Dhall, where you really need it
View bbencoding.dhall
-- https://docs.dhall-lang.org/howtos/How-to-translate-recursive-code-to-Dhall.html
let Person : Type
= (Person : Type)
(MakePerson : { children : List Person, name : Text } Person)
Person
let example : Person
= λ(Person : Type)
λ(MakePerson : { children : List Person, name : Text } Person)
@derrickturk
derrickturk / bbencoding.hs
Created Apr 17, 2021
fun with Boehm-Berarducci encoding
View bbencoding.hs
-- see https://www.haskellforall.com/2021/01/the-visitor-pattern-is-essentially-same.html
{-# LANGUAGE RankNTypes #-}
-- with ADTs:
data Shape
= Circle Double Double Double
| Rectangle Double Double Double Double
deriving (Eq, Show)
@derrickturk
derrickturk / fucky.hs
Last active Mar 31, 2021
typescript is broken, just as much as I originally thought, but in a rather odder way
View fucky.hs
{-# LANGUAGE OverloadedStrings, ViewPatterns, GADTs #-}
import qualified Data.Set as S
import qualified Data.Text as T
data Fucky = Fucky { fuckyNum :: Maybe Double
, fuckyString :: Maybe T.Text
, fuckyFancyString :: Maybe T.Text
, fuckyBoolean :: Maybe Bool
} deriving (Eq, Show)
@derrickturk
derrickturk / boreholes.hs
Last active Mar 19, 2021
Solutions to SWUNG "kata challenges"
View boreholes.hs
-- https://kata.geosci.ai/challenge/boreholes
import Text.Read (readMaybe)
import Data.Array -- Array sucks, but I want to stay inside the standard library
import Data.List (sort)
{- terrible hack! the problem syntax just happens to look
- like the innards of a Haskell list.
-}
parseBoreholes :: String -> Maybe [(Double, Double)]
@derrickturk
derrickturk / poly.ml
Created Mar 11, 2021
working around the lack of rank-2 types in OCaml
View poly.ml
type poly_fn = { f : 'a. 'a -> 'a }
let ap_poly : poly_fn -> int -> bool -> int * bool = fun pf x y ->
(pf.f x, pf.f y)
let ap_poly_obj (obj: <f: 'a. 'a -> 'a>) x y = (obj#f x, obj#f y)
let id x = x
let (x, y) = ap_poly { f = id } 3 true
let (x2, y2) = ap_poly_obj (object method f : 'a. 'a -> 'a = id end) 3 true
@derrickturk
derrickturk / Stlc.fs
Last active Mar 11, 2021
a few STLCs
View Stlc.fs
open System
// types in our system
type Type =
| IntTy
| FnTy of Type * Type
// binary operations on integer expressions
type Op =
| Add
@derrickturk
derrickturk / demo.tsx
Created Feb 10, 2021
React Hooks demo with TypesScript and no funny module-loader business
View demo.tsx
function Counter()
{
const [count, setCount] = React.useState(0);
return (
<div>
<p>Count = {count}</p>
<button onClick={() => setCount(count + 1)}>
Click me! Click me! Do it now, you son of a bitch!
</button>
</div>
@derrickturk
derrickturk / iso.pie
Created Jan 11, 2021
Fun with isomorphisms in Pie
View iso.pie
#lang pie
(claim Vect
(→ U Nat
U))
(define Vect
(λ (A n)
(iter-Nat
n
Trivial
@derrickturk
derrickturk / ackermann.pie
Created Jan 11, 2021
Programs from "The Little Typer"
View ackermann.pie
#lang pie
(claim + (→ Nat Nat Nat))
(define +
(λ (x y)
(iter-Nat x
y
(λ (acc) (add1 acc)))))
(claim repeat
@derrickturk
derrickturk / append_loop_vs_list_comprehension.py
Created Dec 30, 2020
Python - the devil is in the details
View append_loop_vs_list_comprehension.py
Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import dis
>>> def f_list():
... xs = list()
... for i in range(10):
... xs.append(i * i)
... return xs
...
>>> def f_comp():