Skip to content

Instantly share code, notes, and snippets.

View alphaKAI's full-sized avatar

Akihiro Shoji alphaKAI

View GitHub Profile
@alphaKAI
alphaKAI / match.d
Last active September 4, 2017 08:50
toy pattern matching in D
import std.functional,
std.typecons,
std.traits,
std.meta;
class PatternIsNull {}
class PatternWithValue(P = PatternIsNull, F: R delegate(), R: R) {
P pattern;
F func;
@alphaKAI
alphaKAI / notify_send.c
Last active July 17, 2017 14:03
Support callback command when the notification is clicked
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2004 Christian Hammond.
* Copyright (C) 2017 Akihiro Shoji.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
@alphaKAI
alphaKAI / malloc_test.c
Last active July 5, 2017 04:23
mallocの簡単なベンチマーク(DとC)
#include <stdlib.h>
#include <stdio.h>
#define testSize 4194304UL
#define ulong unsigned long long
//#define SHOW
typedef struct test {
ulong id;
char buf[1024];
@alphaKAI
alphaKAI / lambda_normalizer.d
Created May 22, 2017 13:17
ラムダ式のノーマライザをDで書いてみいた
import std.algorithm,
std.format,
std.array;
interface Expr {
string stringof();
string[] freeVars();
void replaceIdentifier(string, string);
Expr dup();
@alphaKAI
alphaKAI / tinylambda.d
Last active April 3, 2017 11:37
Tiny Lambda Expression processor in D
import std.algorithm,
std.format,
std.string,
std.array,
std.stdio;
interface Term {
string toString();
Term apply(Term);
Term apply();
@alphaKAI
alphaKAI / binaryTree.d
Last active January 27, 2017 14:05
Binary Tree with Pattern matching in D
import std.algorithm,
std.traits,
std.format,
std.range,
std.array;
bool instanceof(alias Type, alias Variable)() {
return (cast(Type)Variable) !is null;
}
@alphaKAI
alphaKAI / vmregex.d
Last active January 27, 2017 14:44
VM based regex, in D and Haskell ported from Scala(http://qiita.com/yyu/items/84b1a00459408d1a7321)
import std.stdio;
import std.typecons,
std.format,
std.traits,
std.range;
bool instanceof(alias Type, alias Variable)() {
return (cast(Type)Variable) !is null;
}
@alphaKAI
alphaKAI / output
Created December 9, 2016 08:32
Fractal of Pascal's triangle
-
- -
- * -
- - - -
- * * * -
- - * * - -
- * - * - * -
- - - - - - - -
- * * * * * * * -
- - * * * * * * - -
@alphaKAI
alphaKAI / maybe.d
Last active September 26, 2016 03:21
Maybe Monad in D(I'm studying Haskell thus this code might have a lots of misunderstandings)
import std.traits,
std.conv;
/*
class Functor F where
fmap :: (A -> B) -> FA -> FB
*/
interface Functor(F) {
F fmap(AB = typeof((A _) => B.init), A, B)(AB, F);
@alphaKAI
alphaKAI / typeLevelStack.d
Last active September 21, 2016 14:36
An example of type level stack structure in D.
import std.stdio,
std.traits;
class Type(_type) { alias type = _type; }
class Holder(Types...) {
alias Types Holder;
alias types = Types;
}