Skip to content

Instantly share code, notes, and snippets.

View KeenS's full-sized avatar

κeen KeenS

View GitHub Profile
@KeenS
KeenS / overload.hs
Created June 3, 2018 03:43
GHCで {リスト,スカラ} x {リスト,スカラ}演算のオーバーロード
{-#LANGUAGE TypeFamilies, MultiParamTypeClasses, FlexibleInstances #-}
class Overload a b where
type Out a b :: *
(+):: a -> b -> Out a b
instance Overload Int Int where
type Out Int Int = Int
(+) = (Prelude.+)
@KeenS
KeenS / cli
Last active March 19, 2018 11:36
$ smlsharp -v
SML# 3.4.0 (2017-08-31 19:31:44 JST) for x86_64-pc-linux-gnu with LLVM 3.7.1
$ smlsharp -O3 inner_prod.sml -o inner_prod_smlsharp
$ ./inner_prod_smlsharp
compose
Time:
[Total] 9101 ms/10calls
[Average] 910.1 ms/call
loop
Time:
type Ip = usize;
type Var = usize;
#[derive(Debug)]
enum Instr {
Const(i32),
Add,
Sub,
Get(Var),
Set(Var),
#![recursion_limit = "256"]
// スタックは以下のような形。
// [(マクロ名, (まだ評価していない引数...), (評価が終わった引数...)), ...]
//
// ck(スタック, 式)という形で評価していく。なんとなく継続を起動してるイメージ
// 評価が終わったら`q!(値)`という形で目印を付ける
//
// ただしここで受け取るマクロは全てスタックを第一引数に取るものとする。CPSでいう継続にあたる。
macro_rules! ck {
@KeenS
KeenS / .zshrc
Created January 26, 2018 10:23
Rustでちろっとコード試すのに便利なシェル関数
#!/usr/bin/zsh
# cargo install cargo-scriptしておく。これだけでも便利
# 下記関数でタイプ数節約できる & ツールチェーン切り替えられる
rust() {
local toolchain=+stable
if [[ "$1" =~ "\+.+" ]]; then
toolchain="$1"
@KeenS
KeenS / range.sml
Last active January 25, 2018 06:16
SMLでレンジリテラルっぽいの
datatype range
= to of int * int
| below of int * int
infix to below
structure List = struct
open List
local
A. 本ソフトウェアは Everyone'sWare です。このソフトを手にした一人一人が、
ご自分の作ったものを扱うのと同じように、自由に利用することが出来ます。
A-1. フリーウェアです。作者からは使用料等を要求しません。
A-2. 有料無料や媒体の如何を問わず、自由に転載・再配布できます。
A-3. いかなる種類の 改変・他プログラムでの利用 を行っても構いません。
A-4. 変更したものや部分的に使用したものは、あなたのものになります。
公開する場合は、あなたの名前の下で行って下さい。
B. このソフトを利用することによって生じた損害等について、作者は
$ ghc -O3 fold_elem.hs
$ time ./fold_elem foldr
True
./fold_elem foldr 1.59s user 0.01s system 99% cpu 1.602 total
$ time ./fold_elem foldl
True
./fold_elem foldl 2.96s user 0.01s system 99% cpu 2.978 total
$ time ./fold_elem rec
True
./fold_elem rec 1.63s user 0.00s system 99% cpu 1.638 total
$ cargo build
Compiling swagger_client v1.0.0 (file:///home/kim/Idein/actcast/specification/server)
error: no rules expected the token `.`
--> src/mimetypes.rs:9:97
|
9 | pub static ref PET_FIND_BY_STATUS_GET_SUCCESSFUL_OPERATION: Mime = mime!(Application/Vnd.petstore.v1+json);
| ^
error: aborting due to previous error
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore"
},
"paths": {
"/pet": {
"post": {
"responses": {