Skip to content

Instantly share code, notes, and snippets.

View kazu-yamamoto's full-sized avatar
💭
QUIC and TLS 1.3

Kazu Yamamoto kazu-yamamoto

💭
QUIC and TLS 1.3
View GitHub Profile

function-data/relation mapper

スキーマ

table mail {
    id int primary key,
    from_addr varchar[50],
    date datetime,
    mailbox varchar[50]

}

import Data.Map
import Prelude hiding (lookup)
primes :: [Integer]
primes = sieve [2..]
sieve :: [Integer] -> [Integer]
sieve xs = sieve' xs empty
sieve' :: [Integer] -> Map Integer [Integer] -> [Integer]
module Merge where
merge :: (Ord a) => [a] -> [a] -> [a]
merge xs [] = xs
merge [] ys = ys
merge l@(x:xs) r@(y:ys)
| x < y = x: merge xs r
| otherwise = y: merge l ys
msort :: Ord a => [a] -> [a]
PFDS: Ex 3.1
定理:
Leftistヒープ T において、右のパスの長さが k である場合、
T のノード数 n は
n >= 2^(k+1) - 1
である。
証明:T の高さである h について帰納法で証明する。
@kazu-yamamoto
kazu-yamamoto / gist:2048983
Created March 16, 2012 07:16
Haskell parser with GHC API
-- ghc Main.hs -package ghc
module Main where
import DynFlags
import FastString
import HsSyn
import Lexer
import Outputable
import Parser
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
module Spec (main) where
import Test.HUnit
import System.Process
import System.IO
subprocess = concat $
[ "module Main where\n"
, "import System.IO\n"
, "main = do\n"
@kazu-yamamoto
kazu-yamamoto / gist:2921996
Created June 13, 2012 05:16
String vs ByteString vs Text
{-# LANGUAGE OverloadedStrings #-}
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import Data.ByteString.Char8 ()
import Data.Text (Text)
import qualified Data.Text as T
foo :: String -> Int
module TypeChecker where
type Vname = String
data Vexp = Var Vname
| Lambda Vname Vexp
| Ap Vexp Vexp
| Let [Vname] [Vexp] Vexp
| Letrec [Vname] [Vexp] Vexp
@kazu-yamamoto
kazu-yamamoto / gist:2987415
Created June 25, 2012 08:43
Real Time Queue
{-# LANGUAGE BangPatterns #-}
module RealTimeQueue where
----------------------------------------------------------------
import Control.Applicative ((<$>))
import qualified GHC.Vacuum
import qualified GHC.Vacuum.ClosureType
import System.IO.Unsafe
@kazu-yamamoto
kazu-yamamoto / gist:2987425
Created June 25, 2012 08:45
Scheduled Merge Sort
{-# LANGUAGE BangPatterns #-}
module ScheduledMergeSort where
import Control.DeepSeq
newtype Schedule a = Schedule [[a]] deriving Show
data Segment a = Segment [a] (Schedule a) deriving Show
data MergeSort a = MergeSort Int [Segment a] deriving Show