Skip to content

Instantly share code, notes, and snippets.

View osa1's full-sized avatar

Ömer Sinan Ağacan osa1

View GitHub Profile
@osa1
osa1 / grep.kk
Created June 28, 2025 10:20
Koka example
// Code for the blog post: ...
// Tested with Koka 3.1.2.
import std/os/env
import std/os/file
import std/os/path
fun main()
val args = get-args()
val args-without-flags = args.remove(fn (arg) arg == "--test")
trait Sequence[seq, t, exn]:
forEach(self: seq, consumer: Fn(t) / exn) / exn
# ------------------------------------------------------------------------------
type CountFrom:
from: U32
impl Sequence[CountFrom, U32, exn]:
forEach(self: CountFrom, consumer: Fn(U32) / exn) / exn:
@osa1
osa1 / variants_for_errors.md
Created June 30, 2024 11:35
Anonymous polymorphic variant (sum) types design

Anonymous polymorphic variant (sum) types design

We need a type system that supports the use cases listed below.

Specifically I'm interested in making anonymous sums useful for error handling.

The syntax below are just an example. The final syntax will depend on the type system that will be used to support these use cases.

Also note that the language already has parametric polymorphism with constraints (i.e. typeclasses). The questions about subtyping vs. row poly. below are only for anonymous variants. Named types won't have subtyping.

@osa1
osa1 / syntax_q
Last active June 2, 2024 22:51
Syntax question
-- An evaluator for the language "Untyped Arithmetic Expressions" described in
-- Types and Programming Langauges section 3.
-- Below I have a few different syntax for starting indentation blocks.
--
-- I'm looking for the syntax that is (in priority order)
--
-- (1) Most readable (subjective, I know)
-- (2) Easiest to implement tooling for (e.g. indentatation plugin in text
-- editors)
@osa1
osa1 / main.dart
Last active March 20, 2024 08:05
void main() {
final List<int> list = [1, 2, 3];
final List<num> otherList = list; // unsound, but Dart allows
otherList.add(4.5); // unsoundness above requires runtime check here
}
@osa1
osa1 / linkify.py
Created December 31, 2023 10:48
Convert markdown issue, PR, commit references to GitHub links (written by ChatGPT)
# linkify.py input.md output.md github-username github-repo-name
#
# Converts PR, issue, and commit references to full links.
#
# Written by ChatGPT.
import re
import requests
import argparse
@osa1
osa1 / main.dart
Last active November 23, 2023 12:29
Strange Dart 11
/*
Bad type inference causes breakage when making a type more precise in covariant
position.
*/
class A {
const A();
}
const constA = const A();
@osa1
osa1 / egui_test.rs
Last active September 16, 2023 08:36
use eframe::egui;
fn main() -> Result<(), eframe::Error> {
let options = eframe::NativeOptions {
drag_and_drop_support: true,
initial_window_size: Some(egui::vec2(320.0, 240.0)),
..Default::default()
};
eframe::run_native(
"Native file dialogs and drag-and-drop files",
@osa1
osa1 / main.dart
Created July 19, 2023 12:10
Strange Dart 10
import 'dart:typed_data';
void main() {
final Int32List list = Int32List.fromList([1, 2, 3, 4, 5, 6]);
// Create a view, list without the first and last elements.
final Int32List view = Int32List.sublistView(list, 1, 5);
print(view); // [2, 3, 4, 5, 6]
// Do the same, this time using the `ByteBuffer` object.
@osa1
osa1 / hm.rs
Created June 15, 2023 16:23
HM type inference in Rust
/*
HM type inference with:
- Union-find for unification.
- Type variable levels for generalization.
Implementation became tricky because of the mutable level and link fields.
In this implementations links cannot form cycles (occurs check catches it), so we could use
`Rc<RefCell<..>>`-wrapped types. However: