Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
#include <vector>
// これはテストです
int main()
{
std::vector<char*> v0;
std::cout << "hello" << std::endl;
return 0;
@mmitou
mmitou / supplement2.hs
Created September 17, 2011 17:45
第2回スタートHaskell演習問題
import Data.Char
import Prelude hiding (maximum, minimum, splitAt)
-- ex 5.9
pyths :: Int -> [(Int,Int,Int)]
pyths x | x <= 0 = [(0,0,0)]
| otherwise = [(a,b,c) | a <- [1..x],
b <- [a..x],
c <- [b..x],
@mmitou
mmitou / start_haskell.homework2.hs
Created September 17, 2011 17:53
第2回スタートHaskell宿題
import Data.Char
-- homework 2.1
type Bit = Int
bin2int :: [Bit] -> Int
bin2int = foldr (\x y -> x + 2 * y) 0
int2bin :: Int -> [Bit]
@mmitou
mmitou / 8.hs
Created November 7, 2011 00:29
programming haskell 8
import Prelude hiding (return, (>>=))
import Data.Char
-- 8.2
type Parser a = String -> [(a, String)]
-- 8.3
return :: a -> Parser a
@mmitou
mmitou / pfds.2.hs
Created November 18, 2011 17:04
purely functional data structure 2章の問題の一部
data Tree a = E
| T (Tree a) a (Tree a)
deriving (Show)
empty :: Tree a -> Bool
empty E = True
empty (T _ _ _) = False
insert :: Ord a => a -> Tree a -> Tree a
insert x E = (T E x E)
@mmitou
mmitou / 10.hs
Created December 3, 2011 02:18
programming haskell 10章の問題をちょっとやってみたのの残骸
-- 10.5
data Expr = Val Int | Add Expr Expr
value :: Expr -> Int
value (Val n) = n
value (Add x y) = value x + value y
type Cont = [Op]
data Op = EVAL Expr | ADD Int
@mmitou
mmitou / mona-maybe.hs
Created December 3, 2011 02:19
mwarpとmbindを書くとこんな感じ
import Maybe
mwrap :: a -> Maybe a
mwrap v = Just v
mbind :: Maybe a -> (a -> Maybe b) -> Maybe b
mbind Nothing _ = Nothing
mbind (Just x) f = x
@mmitou
mmitou / mona-parse.hs
Created December 3, 2011 02:21
parserをモナドで書いてみる
import Monad
data Parser a = Parser (String -> [(a, String)])
pwrap :: a -> Parser a
pwrap v = Parser $ \inp -> [(v, inp)]
pbind :: Parser a -> (a -> Parser b) -> Parser b
pbind (Parser p) f = Parser $ \inp -> case p inp of
[] -> []
@mmitou
mmitou / mona-mappable.hs
Created December 3, 2011 02:22
mappableはこんな感じか
class Mappable m where
(<$>) :: (a -> b) -> m a -> m b
mmap :: (a -> b) -> Maybe a -> Maybe b
mmap _ Nothing = Nothing
mmap f (Just x) = Just $ f x
@mmitou
mmitou / leftist-heap.hs
Created December 17, 2011 02:15
leftist-heap pfds ex3.2
data LeftistHeap a = E | T Int a (LeftistHeap a) (LeftistHeap a)
deriving(Show)
rank E = 0
rank (T r _ _ _) = r
makeT x a b = if rank a >= rank b
then T (rank b + 1) x a b
else T (rank a + 1) x b a