Skip to content

Instantly share code, notes, and snippets.

Index: configure.proto
===================================================================
--- configure.proto (revision 35456)
+++ configure.proto (working copy)
@@ -2847,89 +2847,6 @@
fi
dnl check for opengl libs.
- AC_MSG_CHECKING(whether we can use the GL library)
-
use std::marker::PhantomData;
use std::cell::Cell;
struct Scope<'s> {
num: Cell<usize>,
phantom: PhantomData<Cell<&'s mut ()>>,
//ms: Vec<&'s mut i32>, <-- useful trick for understanding lifetimes
}
impl<'s> Scope<'s> {
ALU
Sequence: name=ALUSeq
SetInteger: name=SI00
Sequence: name=Seq.1
SetInteger: name=SI01
Sequence: name=Seq1.
SetInteger: name=SI10
Sequence: name=Seq.1-2
SetInteger: name=SI11
Sequence: name=Decoder
use std::any::TypeId;
use std::any::Any;
fn wrap<F: Fn()+Any>(closure: F) -> extern "C" fn() {
extern "C" fn wrapped<F: Any>() -> () {
println!("Haven't written this yet! TypeId: {:?}", TypeId::of::<F>());
}
println!("Storing closure {:?}", TypeId::of::<F>());
wrapped::<F>
}
@Sgeo
Sgeo / unique_types.rs
Created August 17, 2016 22:43
With help of talchas
#![feature(type_macros)]
struct Zero;
struct Succ<T>(T);
macro_rules! newtype {
($name_:ident) => {
get_and_inc!($name_, Zero);
}
@Sgeo
Sgeo / anymap_spec.rs
Created August 14, 2016 08:23
Specialization-based approach to an AnyMap-like structure
#![feature(specialization)]
#![allow(dead_code)]
struct Nil;
struct Cons<H, T>(H, T);
trait MayContain<T> {
fn get(&self) -> Option<&T>;
fn get_mut(&mut self) -> Option<&mut T>;
}
#![feature(specialization)]
#![allow(dead_code)]
struct Nil;
struct Cons<H, T>(H, T);
struct Zero;
struct Succ<T>(T);
trait At<L> {
#![feature(specialization)]
#![allow(dead_code)]
struct Here;
struct There<T>(T);
struct Nil;
struct Cons<Head, Index, Tail>(Head, Index, Tail);
trait ContainsAt<T, I> {
#![feature(specialization)]
struct Foo;
struct No;
struct Yes;
trait Bar {
type Result;
}
# Demonstration that any Elixir "lens" (function compatible with get_in and get_and_update_in) is equivalent to a lens represented in get/set style
# Modulo the fact that an Elixir lens cannot be written if there is no valid "get" operation
defmodule Optics do
defp id, do: fn x -> x end
defp old_and_new(new), do: fn old -> {old, new} end
def decompose(lens) do
[get: fn(obj) -> lens.(:get, obj, id) end,
set: fn(obj, new) -> lens.(:get_and_update, obj, old_and_new(new)) |> elem(1) end]