Skip to content

Instantly share code, notes, and snippets.

edmundsmith /
Created July 7, 2019 20:47
Method for Emulating Higher-Kinded Types in Rust

Method for Emulating Higher-Kinded Types in Rust


I've been fiddling about with an idea lately, looking at how higher-kinded types can be represented in such a way that we can reason with them in Rust here and now, without having to wait a couple years for what would be a significant change to the language and compiler.

There have been multiple discussions on introducing higher-ranked polymorphism into Rust, using Haskell-style Higher-Kinded Types (HKTs) or Scala-looking Generalised Associated Types (GATs). The benefit of higher-ranked polymorphism is to allow higher-level, richer abstractions and pattern expression than just the rank-1 polymorphism we have today.

As an example, currently we can express this type:

Raw Trait Objects 1.0

This is the sketch of a proposal for making it possible to manipulate some trait objects in stable rust.

Proposed new/stabilized API:

mod std::raw {
johnhw /
Last active January 6, 2024 16:09
1 million prime UMAP layout
### JHW 2018
import numpy as np
import umap
# This code from the excellent module at:
import random
mikeyhew /
Last active June 5, 2018 06:20
DerefMove and DerefInto
#![feature(arbitrary_self_types, specialization)]
use std::{
mem::{self, ManuallyDrop},
ptr::{self, NonNull},
ops::{Deref, DerefMut},
struct Move<'a, T: 'a + ?Sized> {
cessen /
Last active January 26, 2018 22:33
#Rust2018 blog post


This is my contribution to the call for Rust blog posts.

I've been using Rust for various personal projects for quite a while now, and I confess that I have a lot to say about it! In fact, I've already said quite a bit about it before.

My experience with Rust has been overwhelmingly positive, and most of the things I still want (e.g. NLL, const functions, const generic parameters, SIMD intrinsics, etc.) are already well known and being worked on, so it seems silly to repeat them. Therefore, in this post I'm just going to highlight three small-ish things that have been mildly frustrating to me over the last year, but which I haven't seen mentioned recently.

BidirectionalIterator trait

Cretonne IL is tuned for codegen. You can see this in the use of EBBs, br_table
not taking arguments, the lack of builtin def-use lists, the lack of a
general-purpose switch statement, the precense of instructions specialized to
take an immediate argument, and other places.
I'm entertaining the idea that this works out well for Rustc. It'll make
"fast compile" use cases, both "debug" and "pretty good optimization" builds
faster. Compared to LLVM's 4 layers in a typical compile (LLVM IR, SelectionDAG,
MachineFunction, MC), Cretonne uses one IL throughout, and it's designed
to be very compact.
kyleheadley /
Created August 2, 2017 22:19
Implement the untyped lambda calculus in the Rust type system.
// Booleans
struct True;
struct False;
trait BoolOr<B> {type BoolOr;}
impl<B> BoolOr<B> for True {type BoolOr=True;}
impl BoolOr<True> for False {type BoolOr=True;}
impl BoolOr<False> for False {type BoolOr=False;}
kristovatlas / cssbanner-beautified2.js
Last active March 9, 2018 21:49
cleaned up version of cssbanner.js
//beautified at with default options
//and then manually modified
/*jslint bitwise: true */
self.onmessage = function (msg) {
var thecode =;
* Ostensibly unused function
baffo32 / rolling_sphere.txt
Created August 29, 2016 12:37
Rolling Sphere
precision highp float;
precision mediump float;
uniform vec2 resolution;
#define FTIME_PERIOD 16.0
uniform float ftime;
uniform float subsecond;
jkoelker / gaming
Last active June 3, 2023 23:30
Enable or Disable the Touchpad while typing via libinput `xinput` (aka. libinput "gaming" mode)
# libinput by default will disable the touchpad while a key is pressed.
# to disable this, run `xinput` to list the inputs. find the name of your
# touchpad (mine is 'Microsoft Surface Keyboard Touchpad').
# Disable the setting 'Disable While Typing Enabled'
# `xinput --set-prop 'Microsoft Surface Keyboard Touchpad' \
# 'libinput Disable While Typing Enabled' 0`