Skip to content

Instantly share code, notes, and snippets.

View derrickturk's full-sized 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 / fucky.hs
Last active March 31, 2021 22:08
typescript is broken, just as much as I originally thought, but in a rather odder way
{-# 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 March 19, 2021 19:42
Solutions to SWUNG "kata challenges"
-- 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 March 11, 2021 22:00
working around the lack of rank-2 types in OCaml
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 March 11, 2021 18:00
a few STLCs
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 February 10, 2021 18:16
React Hooks demo with TypesScript and no funny module-loader business
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 January 11, 2021 01:06
Fun with isomorphisms in Pie
#lang pie
(claim Vect
(→ U Nat
U))
(define Vect
(λ (A n)
(iter-Nat
n
Trivial
@derrickturk
derrickturk / ackermann.pie
Created January 11, 2021 00:11
Programs from "The Little Typer"
#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 December 30, 2020 16:29
Python - the devil is in the details
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():
@derrickturk
derrickturk / csv_merge.py
Created December 16, 2020 17:12
merge structurally similar CSV files in "per-case" directories, tagging rows
import sys
import os
import os.path
import csv
from typing import List, Optional, Set
# given a list of directories d1, d2, d3
# each containing a common set of CSV files with the same columns:
# d1/a.csv d1/b.csv
@derrickturk
derrickturk / badlist.hs
Created December 15, 2020 21:18
more bad lists
{-# LANGUAGE RankNTypes #-}
newtype Listy a = Listy { runListy :: forall b . (a -> b -> b) -> b -> b }
nil :: Listy a
nil = Listy $ \_ init -> init
cons :: a -> Listy a -> Listy a
cons x xs = Listy $ \fn init -> fn x (runListy xs fn init)