Skip to content

Instantly share code, notes, and snippets.

We couldn’t find that file to show.
@takoeight0821
takoeight0821 / GIf.hs
Last active December 2, 2019 07:08
generic 'if'
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module GIf where
import Data.Kind
import GHC.Generics
import Prelude
@takoeight0821
takoeight0821 / Main.hs
Last active November 3, 2019 12:37
エキゾチックなNumインスタンス
module Main where
newtype IODouble = IODouble { runIODouble :: IO Double }
instance Num IODouble where
fromInteger x = IODouble $ do
print x
pure $ fromInteger x
(IODouble x) + (IODouble y) = IODouble $ do
x' <- x
@takoeight0821
takoeight0821 / foo.s
Created August 31, 2019 15:45
Arch Linuxでclang -c foo.sでこれコンパイルするとclangがセグフォする
.intel_syntax noprefix
.text
not:
ret
f:
call not
ret
# 以下ログ
# Stack dump:
@takoeight0821
takoeight0821 / main.c
Last active April 16, 2019 13:12
zamの実装っぽい何か
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <gc.h>
#include <stdint.h>
struct value;
struct env
{
@takoeight0821
takoeight0821 / main.c
Last active April 13, 2019 07:28
スタックマシンっぽい何か
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <gc.h>
union value;
struct env;
struct closure;
union value;
@takoeight0821
takoeight0821 / main.js
Last active February 5, 2019 05:26
ダブルクロス対応のダイスbot
const Discord = require('discord.js');
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
}
function diceRoll(count, roll) {
let dices = [];
@takoeight0821
takoeight0821 / main.cc
Last active December 11, 2018 12:21
競プロの簡単な問題を解いたときの副産物
#include <iostream>
#include <tuple>
#include <algorithm>
#include <vector>
using namespace std;
template <typename T>
unsigned int digit_sum(T x, unsigned int base) {
auto result = 0;
@takoeight0821
takoeight0821 / main.c
Created December 7, 2018 16:14
逆ポーランド記法電卓っぽい何か
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LEN 256
typedef struct stack {
int *stack;
int len;
} Stack;
@takoeight0821
takoeight0821 / AstDsl.hs
Created November 28, 2018 03:37
ASTを構築する言語内DSLについて色々考えたメモ
module AstDsl where
import Control.Monad.State
import Control.Monad.Identity
import Data.Monoid
import Control.Monad.Writer
-- こんな普通のAST定義があるとする
data Expr = Let String Expr Expr
| Var String