Skip to content

Instantly share code, notes, and snippets.

@aslpavel
aslpavel / writeup.md
Created July 10, 2019 23:39 — forked from edmundsmith/writeup.md
Method for Emulating Higher-Kinded Types in Rust

Method for Emulating Higher-Kinded Types in Rust

Intro

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:

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@aslpavel
aslpavel / ad.py
Last active December 16, 2018 18:55
Simple implementation of automatic differentiation and SVM in python
"""Simple implementation of atomatic differentiation
"""
import math
import inspect
import numpy as np
def apply(fn, *args, **kwargs):
return fn(*args, **kwargs)
@aslpavel
aslpavel / list.rs
Last active October 9, 2020 11:07 — forked from rust-play/playground.rs
List abstracted over Rc/Arc
// https://play.rust-lang.org/?gist=6f69dfefc6dd93d941cabb9a1634dcee
use std::fmt;
use std::iter::FromIterator;
use std::rc::Rc;
use std::sync::Arc;
use std::ops::Deref;
// pub trait HKT<U> where U: ?Sized {
// type C; // Current type
// type T; // Type with C swapped with U
@aslpavel
aslpavel / .ctags
Last active May 24, 2018 16:17
building ctags for mononoke
--langdef=Rust
--langmap=Rust:.rs
--regex-Rust=/^[ \t]*(#\[[^\]]\][ \t]*)*(pub(\(crate\))?[ \t]+)?(extern[ \t]+)?("[^"]+"[ \t]+)?(unsafe[ \t]+)?fn[ \t]+([a-zA-Z0-9_]+)/\7/f,functions,function definitions/
--regex-Rust=/^[ \t]*(pub(\(crate\))?[ \t]+)?type[ \t]+([a-zA-Z0-9_]+)/\3/T,types,type definitions/
--regex-Rust=/^[ \t]*(pub(\(crate\))?[ \t]+)?enum[ \t]+([a-zA-Z0-9_]+)/\3/g,enum,enumeration names/
--regex-Rust=/^[ \t]*(pub(\(crate\))?[ \t]+)?struct[ \t]+([a-zA-Z0-9_]+)/\3/s,structure names/
--regex-Rust=/^[ \t]*(pub(\(crate\))?[ \t]+)?(static|const)[ \t]+(mut[ \t]+)?([a-zA-Z0-9_]+)/\5/c,consts,static constants/
--regex-Rust=/^[ \t]*(pub(\(crate\))?[ \t]+)?(unsafe[ \t]+)?trait[ \t]+([a-zA-Z0-9_]+)/\4/t,traits,traits/
--regex-Rust=/^[ \t]*(pub(\(crate\))?[ \t]+)?(unsafe[ \t]+)?impl([ \t\n]*<[^>]*>)?[ \t]+(([a-zA-Z0-9_:]+)[ \t]*(<[^>]*>)?[ \t]+)?(for[ \t]+)?([a-zA-Z0-9_]+)/\9/i,impls,trait implemented for/
--regex-Rust=/^[ \t]*(pub(\(crate\))?[ \t]+)?(unsafe[ \t]+)?impl([ \t\n]*<[^>]*>)?[ \t]+(([a-zA-Z0-9_:]
#! /usr/bin/env python3
import os
import re
import sys
import subprocess
def error(msg, code=1):
sys.stderr.write('[error] {}\n'.format(msg))
sys.exit(code)
@aslpavel
aslpavel / config.fish
Last active December 19, 2015 10:19
Simple config.fish with nice prompt
# Simple config.fish with nice prompt (requires patched powerline font)
# link: https://gist.github.com/aslpavel/5939845
# install: wget --no-check-certificate -q -O - https://gist.github.com/aslpavel/5939845/download | tar -xzO -f- --strip-components=1 > "$HOME/.config/fish/config.fish"
### PROMPT
switch "$TERM"
case "linux" "rxvt"
set _prompt_sep ""
set _prompt_col_user 3
set _prompt_col_host 3
@aslpavel
aslpavel / bashrc
Last active October 6, 2022 16:49
Simple bashrc with nice prompt
# simple bashrc with nice prompt
# link: https://gist.github.com/aslpavel/5925739
# install: wget --no-check-certificate -q -O - https://gist.github.com/aslpavel/5925739/download | tar -xzO -f- --strip-components=1 > "$HOME/.bashrc"
[ -z "$PS1" ] && return
### PROMPT
case $TERM in
linux|rxvt)
col_user=3
@aslpavel
aslpavel / pretzel_cat.py
Last active December 17, 2015 15:59
Cat remote file over ssh (with pretzel framework)
"""Cat remote file over ssh
pretzel framework: https://github.com/aslpavel/pretzel
"""
from __future__ import print_function
import os
import sys
from pretzel.app import app
from pretzel.monad import async
from pretzel.remoting import SSHConnection
@aslpavel
aslpavel / pretzel_echo.py
Last active December 17, 2015 15:59
Simple echo server (with pretzel framework)
"""Simple echo server
pretzel framework: https://github.com/aslpavel/pretzel
"""
from __future__ import print_function
import sys
import socket
from pretzel.app import app
from pretzel.monad import async
from pretzel.uniform import BrokenPipeError