Skip to content

Instantly share code, notes, and snippets.

View eernstg's full-sized avatar

Erik Ernst eernstg

  • Google
  • Aarhus, Denmark
View GitHub Profile
// ----------------------------------------------------------------------
// Basic example, hypothetical code only.
// typeclass Index<inout X, in Y> {
// X X.operator [](Y y);
// }
// instance Index<int, int> {
// int int.operator [](int y) => this + y;
// }
// define an example struct, make it printable
#[derive(Debug)]
struct Foo;
// an example trait
trait Bar {
fn baz(&self);
}
// implement the trait for Foo
@eernstg
eernstg / typeclass_example.dart
Last active March 24, 2022 14:45
Typeclass example
/*
Several examples, separated by '-----' lines.
We probably want to use a regular type variable declaration list plus
a constraint specification list (to request a dispatcher object for a
specific typeclass instance), so I'm using `where` clauses in various
headers.
Dispatcher objects are holders of functions, and there is no particular
notion of a receiver, so we're likely to benefit _greatly_ from sound
@eernstg
eernstg / swiftUI.dart
Last active December 17, 2021 00:46
Illustrating the effect of making parameters named `child` and `children` optionally named (and using `named-parameters-anywhere`).
void main() {
AnimatedContainer(
SizedBox(
height: 57,
Row([
if (widget.icon != null)
SizedBox(height: 29, width: 29, widget.icon),
Expanded(
Column([
const SizedBox(height: 8.5),
abstract class Person {
String name;
String address;
}
class DelegatorPerson implements Person {
DelegateePerson delegatee;
DelegatorPerson(this.delegatee);
String get name => delegatee.name(this);
set name(String value) => delegatee.nameSet(this, value);
@eernstg
eernstg / main.dart
Last active November 4, 2019 14:45
Code for comment on 'How language features affect OO design'
main() {
new Dog().feed("some food");
}
abstract class Pet {
void feed(String food);
void pet();
}
class Dog = Pet with FeedableDog, PettableDog;
@eernstg
eernstg / int-to-double.md
Last active August 14, 2018 13:37
Dart Feature Specification: Evaluating integer literals as double values
________ running '/usr/bin/python sdk/tools/generate_buildfiles.py' in '/usr/local/google/home/eernst/devel/dart/work'
Command failed: /usr/local/google/home/eernst/devel/dart/work/sdk/buildtools/linux-x64/gn gen out/DebugIA32 --args=dart_zlib_path="//runtime/bin/zlib" exclude_kernel_service=false is_product=false dart_runtime_mode="develop" dart_stripped_binary="exe.stripped/dart" use_goma=false dart_platform_sdk=false dart_use_wheezy_sysroot=true is_msan=false is_release=false is_clang=true dart_target_arch="ia32" dart_use_tcmalloc=true goma_dir="None" dart_debug=true host_cpu="x86" dart_snapshot_kind="script" is_tsan=false target_os="linux" dart_use_fallback_root_certificates=true target_cpu="x86" is_asan=false is_debug=true
output: ERROR at //build/dart/dart_action.gni:232:11: Assignment had no effect.
"$_dart_root/tools/sdks/dart-sdk/bin/snapshots/kernel-service.dart.snapshot"
^---------------------------------------------------------------------------
You set the variable "dfe" here
@eernstg
eernstg / extreme-upper-lower-bounds.md
Last active May 22, 2018 16:13
Dart 2 feature specification of top/bottom type upper and lower bounds

This document may be obsolete, or it may be a proposed new version; if in doubt please consider the version in the SDK repository (which may not yet exist).

Feature Specification: Upper and Lower Bounds for Extreme Types

Owner: eernst@

Status: Under discussion.

bool b = false;
void doWork(int i) => print("Do work ($i)");
void bailOut(int i) => print("Bail out ($i)");
void acquire() => print("Acquire the resource");
void release() => print("Release the resource");
// Consider: We want to simplify the following control flow.