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 / good.hs
Last active November 30, 2022 22:04
hell with type-level map
{-# LANGUAGE DataKinds, GADTs, KindSignatures, TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
module Data.HList
( HList(..)
, TypeMap
) where
import Data.Kind (Type)
import Data.Maybe (fromJust, fromMaybe)
@derrickturk
derrickturk / base26.hs
Last active November 21, 2022 20:53
say, Excel column names, super inefficiently
base26 :: Integer -> String
base26 n =
let (m, n') = n `divMod` 26
ones = [toEnum (fromEnum 'A' + fromInteger n')]
in case m of
0 -> ones
m -> base26 (m - 1) ++ ones
@derrickturk
derrickturk / rev_ll.c
Created October 26, 2022 14:49
every time I see someone bitch about "reversing linked lists" I have this terrible compulsion
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
typedef struct node {
int value;
struct node *next;
} node, *list;
void list_free(list l)
@derrickturk
derrickturk / cpu.pony
Last active September 18, 2022 17:42
AoC 2019/07, but it crashes the Pony runtime
use "collections"
interface Sendable
fun tag send(word: I64)
primitive Running
primitive Blocked
primitive Halted
primitive IllegalInstruction
@derrickturk
derrickturk / abstype.kk
Created July 29, 2022 03:01
"Abstract"-ish types in Koka (and module naming whatevers)
abstract type meat
Beef
pub Lamb(age: int)
@derrickturk
derrickturk / vecs.kk
Created July 29, 2022 02:30
Fun with heap and vector in Koka
fun iota_vec(n: int): vector<int>
vector-init(n, id)
fun oddity(n: int): exn vector<int>
var v := iota_vec(n)
for(0, n) fn(i)
v[i] := v[i] + 3
v
fun space-oddity(n: int): exn vector<int>
@derrickturk
derrickturk / ext.kk
Created July 29, 2022 02:06
Extensible variant types (I think? they're not documented except in the grammar) in Koka
open type openvar
A
B
extend type openvar
C
fun do_it_try_it(v: openvar): console ()
match v
A -> println("got an A")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@derrickturk
derrickturk / save.eff
Created July 23, 2022 03:47
now this is podracing
(* yeah, so, Eff doesn't actually support polymorphic effects *)
effect Save: string -> int
effect Load: string * int -> empty
let save name = perform (Save name)
let load name v = absurd (perform (Load (name, v)))
let savegames = handler
| effect (Save name) k ->
@derrickturk
derrickturk / quicksave.eff
Last active July 23, 2022 03:32
play a game of "Guess or Die", with aggressive save-scumming
effect QuickSave: int option
effect QuickLoad: int -> empty
let quicksave () = perform QuickSave
let quickload n = absurd (perform (QuickLoad n))
let quicksaving = handler
| effect QuickSave k ->
let rec quickloading () = handler
| effect (QuickLoad n) _ ->