Skip to content

Instantly share code, notes, and snippets.

View zesterer's full-sized avatar

Joshua Barretto zesterer

View GitHub Profile
@zesterer
zesterer / infer.rs
Created May 14, 2020 21:28
Type Inference in 66 lines of Rust
use std::collections::HashMap;
#[derive(Debug)]
enum Type {
Num,
Bool,
List(Box<Type>),
Func(Box<Type>, Box<Type>),
}
diff --git a/src/lib.rs b/src/lib.rs
index 24534a8..8121dd9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -170,6 +170,11 @@ fn wait_lock<'a, T>(lock: &'a InnerMutex<T>) -> MutexGuard<'a, T> {
}
}
+#[inline]
+fn poll_lock<'a, T>(lock: &'a InnerMutex<T>) -> Option<MutexGuard<'a, T>> {
hydra-32t-1m-flume time: [89.310 us 90.372 us 91.435 us]
Found 6 outliers among 100 measurements (6.00%)
4 (4.00%) high mild
2 (2.00%) high severe
hydra-32t-1m-floom time: [98.935 us 100.76 us 102.84 us]
Found 6 outliers among 100 measurements (6.00%)
5 (5.00%) high mild
1 (1.00%) high severe
Arch Linux, 4 cores, 8 threads, AMD Ryzen 7
===========================================
create-flume time: [133.58 ns 133.99 ns 134.43 ns]
change: [-2.8490% -2.1632% -1.5710%] (p = 0.00 < 0.05)
Performance has improved.
create-crossbeam time: [189.86 ns 190.24 ns 190.67 ns]
change: [+1.3594% +1.8473% +2.3118%] (p = 0.00 < 0.05)
Performance has regressed.
#!/usr/bin/env bash
set -e
cweb_version=0.6.26
cweb=https://github.com/koute/cargo-web/releases/download/$cweb_version/cargo-web-x86_64-unknown-linux-gnu.gz
curl -Lo cargo-web.gz $cweb
gunzip cargo-web.gz
chmod u+x cargo-web
#!/usr/bin/env bash
set -e
cweb_version=0.6.26
cweb=https://github.com/koute/cargo-web/releases/download/$cweb_version/cargo-web-x86_64-unknown-linux-gnu.gz
curl -Lo cargo-web.gz $cweb
gunzip cargo-web.gz
chmod u+x cargo-web
# Find the length of a list
def len = l ->
if l = []
then 0
else len(:> l) + 1
# Find the nth element in a list
def nth = n -> l ->
if n < 1
then <: l
# Sum types with type parameters
data Maybe T =
| Some T
| None
data Pet =
| Dog
| Cat
| Hamster
const std = struct {
io: struct {
print: |msg| {
__print(msg);
},
println: |msg| {
self.print(msg + "\n");
},
input: || {
__input()
use std::{
collections::{HashMap, VecDeque, hash_map::DefaultHasher},
hash::{Hash, Hasher, BuildHasherDefault, BuildHasher},
};
#[derive(Debug)]
pub enum Error {
NoSuchHash,
DuplicateHash,
}