Skip to content

Instantly share code, notes, and snippets.

View eernstg's full-sized avatar

Erik Ernst eernstg

  • Google
  • Aarhus, Denmark
View GitHub Profile
enum Key {
key1,
key2;
T mapFor<T>({
required T Function() key1,
required T Function() key2,
}) {
switch (this) {
case Key.key1: return key1();
// ----------------------------------------------------------------------
// 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 / super-bounded-types.md
Last active October 16, 2018 13:42
Informal specification: Super-bounded Types
@eernstg
eernstg / InstantiateToBound.md
Last active October 16, 2018 11:14
Informal specification of the instantiate to bound mechanism.

This document may be obsolete, if in doubt please refer to the version in the SDK repository.

Feature: Instantiate to Bound

Author: eernst@

Version: 0.9 (2018-10-16)

Status: Implemented.

@eernstg
eernstg / dynamic-members.md
Last active September 4, 2018 14:26
Static analysis of members of dynamic

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).

Typing of members of dynamic

Author: eernst@.

Version: 0.2 (2018-09-04)