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 / 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:
@osa1
osa1 / main.dart
Last active January 26, 2023 15:52
Strange Dart 9 (2)
import 'my_library.dart';
// Same class B in Strange Dart 9.1, but this time it's accepted.
class B implements A {}
void main() {
wat(B()); // _a getters and setters redirect to noSuchMethod
}
@osa1
osa1 / main.dart
Last active January 26, 2023 15:48
Strange Dart 9 (1)
// Private members are not part of a class's interface, but implementing
// classes need to implement them.
//
// ... except when the class being implemented is in a separate library. See
// the second part: https://gist.github.com/osa1/a6b70f36d1041996c3ff7fa12c7589d8
class A {
int _a = 1;
int _b = 2;
@osa1
osa1 / main.dart
Last active January 24, 2023 17:35
Strange Dart 8
class A {
@override
Type get runtimeType => int;
}
class B<T> {}
void main() {
print(A().runtimeType); // int
print(B<A>().runtimeType); // B<A>
@osa1
osa1 / main.dart
Last active January 20, 2023 09:43
Strange Dart 7
// Almost by definition, if I'm able to pass X where Y is expected, then X is a
// subtype of Y.
//
// In Dart, this mostly holds, but `dynamic` is an exception. I can pass
// `dynamic` everywhere, but it's not really a subtype of anything.
void f(int a) {}
class C<A> {}