Skip to content

Instantly share code, notes, and snippets.

@chpatrick
chpatrick / baked.hs
Last active August 10, 2021 18:11
Baked-in Storable vectors
{-# LANGUAGE QuasiQuotes, TemplateHaskell, ScopedTypeVariables #-}
module BakedVector where
import qualified Data.ByteString.Lazy as BSL
import Data.ByteString.Lazy (unpack)
import Data.ByteString.Builder (toLazyByteString)
import Data.ByteString.Builder.Prim
import Foreign.Storable
import qualified Data.Vector.Storable as VS
@puffnfresh
puffnfresh / reornament.idr
Last active September 15, 2018 21:20
Algebraic Ornaments!
module reornament
-- Idris translation of Agda code:
-- https://gist.github.com/gallais/e507832abc6c91ac7cb9
-- Which follows Conor McBride's Ornaments paper:
-- https://personal.cis.strath.ac.uk/conor.mcbride/pub/OAAO/Ornament.pdf
ListAlg : Type -> Type -> Type
ListAlg A B = (B, A -> B -> B)
module ActiveSupport::Concern
def append_features(base)
if base.instance_variable_defined?("@_dependencies")
base.instance_variable_get("@_dependencies") << { :module => self, :method => :include }
return false
else
return false if base < self
@_dependencies.each { |dep| base.send(dep[:method], dep[:module]) }
super
base.extend const_get("ClassMethods") if const_defined?("ClassMethods")
@kballenegger
kballenegger / fib.c
Created May 13, 2013 04:59
Fibonacci generator in C with Y-Combinator powered memoization.
//
// Fibonacci generator in C with Y-Combinator powered memoization.
//
// Written by Kenneth Ballenegger in 2013
//
#include <stdlib.h>
#include <stdio.h>
#include <Block.h>
@philsquared
philsquared / C++ Extension Methods
Created April 11, 2013 23:45
How to write the "left arrow operator" to enable extension methods in C++
#include <cassert>
#include <iostream>
template<typename T, typename R=void>
struct ExtMethod {
ExtMethod& operator - () {
return *this;
}
template<typename U>