Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE UndecidableInstances #-}
module Fix where
-- Definitions:
--
-- If (μF,inF) is the initial F-algebra for some endofunctor F
@yuga
yuga / redblacktree.py
Last active June 9, 2018 20:52
CLRS 2ndのRed-Black Tree あってるかどうか... 番兵のparent, left, right, keyは操作の都合上値置場として活用することがある(日本語版第二版P269)。
#!/bin/env python
# -*- coding: utf-8 -*-
class Color:
RED = 1
BLACK = 2
class Element:
def __init__(self, key):
self.key = key
@yuga
yuga / Microsoft SQL Server 環境の構築.md
Last active October 5, 2016 09:35
WindowsにSQL Server 2012 Expressをインストールして、Linux上のHaskellからODBCで接続できるようになるまで。

Microsoft SQL Server 環境の構築

  • Server: Widnwos & SQL Server
  • Client: Linux

Microsoft SQL Server 2012 Express のインストール方法

@yuga
yuga / gist:8255552
Last active September 11, 2016 05:34

Haskellでバイナリデータ

1. はじめに

Haskellでバイナリファイルの読み書きをすることがこれまで何回かあったので、それをネタにアドベントカレンダーに参加したつもりだったのですが、定刻よりもだいぶ遅れての年始の到着となりました。申し訳ございません。これはHaskell Advent Calender 2013 11日目だったはずの記事です。明けましておめでとうございます。

さて。コンンピュータで扱うデータはすべてバイナリ形式で表現されています。したがってすべてはバイナリデータであるという言い方ができますが、しかし一般には、テキストでないデータをバイナリデータと呼びます。

Haskellにはバイナリデータを扱うライブラリがたくさんあります。どのライブラリも特別難しい要素があるわけでなく、Haskellのライブラリの中では扱いの容易な部類に含まれるものと思います。しかし、初めて取り組むときには、主要なライブラリのどれも同じようなインターフェイスを提供していることに、何を選べば良いか戸惑う人も多いのではないでしょうか。

{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
module ReflectionTest where
import Data.Proxy
import Unsafe.Coerce

GHC管理のメモリを表現する型の違い

        | Immutable   | Mutable           
--------|-------------|-------------------
Boxed   | Array#      | MutableArray#
--------|-------------|-------------------
Unboxed | ByteArray#  | MutableByteArray#
------------------------------------------
@yuga
yuga / Bin.hs
Created November 10, 2013 06:53
What to do to make this to be used as a library?
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MagicHash #-}
module Bin where
import Control.Applicative (Applicative(..), (<$>))
import Control.Monad (ap)
import qualified Data.Array.MArray as M
import Data.Array.Storable hiding (getBounds)
import qualified Data.Array.Unsafe as U
@yuga
yuga / lcs_length.py
Created October 27, 2013 03:54
アルゴリズムイントロダクション 2巻 第3版 練習問題15.4-2, 15.4-3, 15.4-4
# -*- coding: utf-8 -*-
import codecs
import sys
class Matrix:
def __init__(self, rows, columns, value=0):
self.rows = rows
self.columns = columns
self.mat = [[value for _ in range(columns)] for _ in range(rows)]
@yuga
yuga / gist:6612105
Last active December 23, 2015 09:09
Add support for cabal sandbox to syntastic. Write this in your .vimrc.
function! s:get_cabal_sandbox()
if filereadable('cabal.sandbox.config')
let l:output = system('cat cabal.sandbox.config | grep local-repo')
let l:dir = matchstr(substitute(l:output, '\n', ' ', 'g'), 'local-repo: \zs\S\+\ze\/packages')
return '-s ' . l:dir
else
return ''
endif
endfunction
@yuga
yuga / add.sql
Last active December 19, 2015 04:48
/* LearningSQLExample.sql
from http://examples.oreilly.com/9780596007270/LearningSQLExample.sql
Modified for PostgreSQL.
% psql -f add.sql
*/
/* begin table creation */
create table department
(dept_id serial,