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 について帰納法で証明する。 |
-- 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" |
{-# 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 |
{-# LANGUAGE BangPatterns #-} | |
module RealTimeQueue where | |
---------------------------------------------------------------- | |
import Control.Applicative ((<$>)) | |
import qualified GHC.Vacuum | |
import qualified GHC.Vacuum.ClosureType | |
import System.IO.Unsafe |
{-# 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 |