Skip to content

Instantly share code, notes, and snippets.

@maoe
maoe / CPSOptimization.hs
Created April 30, 2011 14:14
モナドをCPS変換して高速化する
{-# LANGUAGE Rank2Types, ViewPatterns #-}
{-|
Asymptotic Improvement of Computations over Free Monadsより
通常のmonadicなコードでO(n^2)かかる計算を手でCPS変換あるいはContTモナド
を使ってCPS変換させてO(n)に改善する。
-}
module Main where
@maoe
maoe / MotherCont.hs
Created April 30, 2011 16:39
継続モナドはすべてのモナドの母である
{-|
A Neighborhood of Infinity: The Mother of all Monadsより
継続モナドはすべてのモナドの母であることを示すサンプルコード
-}
module MotherCont where
import Control.Monad.Cont (runCont, cont)
ex1 = do
@maoe
maoe / repro.c
Last active March 31, 2021 01:37
// cc -o repro repro.c libopenblas.a
// or
// cc -o repro repro.c -L. -lopenblas
// then
// ./repro
#include <stdio.h>
#include "cblas.h"
int main(void)
{
@maoe
maoe / repro.rs
Last active March 18, 2021 07:05
fn main() {
let v: f64 = 1.1276353206339418;
assert_eq!(v.ln(), 0.12012280349368988);
}
@maoe
maoe / Foo.hs
Last active February 28, 2021 13:32
Minimum repro for a GHCi panic due to linkSomeBCOs: no break array
module Foo (Foo(..)) where
class Foo a where
bar :: a -> ()
bar _ = ()
<!DOCTYPE HTML><html><head><title>Criterion comparison</title><meta charset="UTF-8"><style>
.stddev
{
font-size : x-small;
}
td
{
padding-left : 1em;
padding-right : 1em;
{-# LANGUAGE BangPatterns #-}
module Main where
import Data.Char
import Data.List
import Data.List.Split
import Criterion.Main
commafyFoldr :: String -> String
commafyFoldr = snd . foldr f (0 :: Int, "")
where

UnboxedSums

GHC 8.2.1で実装された言語拡張。anonymousでunboxedな直和型を実現する機能。

例: Maybe#

{-# LANGUAGE MagicHash #-} -- Maybe#のハッシュ記号に必要
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-} -- a :: TYPE rに必要
@maoe
maoe / update.sh
Created November 17, 2018 14:07
Update symlinks for GHC
#!/bin/bash
EXECUTABLES="ghc ghc-pkg ghci haddock runghc"
VERSION=$1
if [ -z "$1" ]; then
echo "ERROR: GHC version number needs to be specified. Exiting." 1>&2
exit 1
fi
pushd /opt/ghc/bin > /dev/null
@maoe
maoe / TODO.md
Last active March 31, 2018 05:05
TODO for threadscope
  • Make application settings (e.g. default window size, checkboxes in the Traces tab etc) persistent

  • Switch to GTK+3 for better HiDPI support

  • Display duration in the status bar when dragging on the timeline

  • Checkbox to display/hide event markers

  • Drag support in the raw events

  • Search text in the raw events

  • Filter by thread ID (like "follow tcp stream" in wireshark)

  • Tooltip that displays the thread name or ID of the area under the cursor

  • Build index (with succinct/compact data structures) to save memory usage