This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| deleteMin :: Ord a => [a] -> [a] | |
| deleteMin xs@(x:_) = snd $ para f (x,[]) xs | |
| where | |
| f x (xs,(y,_)) | |
| | x < y = (x,xs) | |
| | otherwise = (y,x:xs) | |
| para :: (a -> ([a],b) -> b) -> b -> [a] -> b | |
| para _ z [] = z | |
| para f z (x:xs) = f x (xs, para f z xs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ sudo apt-get update | |
| $ sudo apt-get upgrade |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module DelayList where | |
| import Control.Concurrent (threadDelay) | |
| import System.IO.Unsafe (unsafeInterleaveIO) | |
| delayList :: Int -> [a] -> IO [a] | |
| delayList _ [] = unsafeInterleaveIO $ return [] | |
| delayList i (x:xs) | |
| = unsafeInterleaveIO $ threadDelay i >> delayList i xs >>= return . (x:) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.List (mapAccumR) | |
| pascal :: [[Integer]] | |
| pascal = [1] : [f cs | cs <- pascal ] | |
| where | |
| f xs = snd $ mapAccumR g xs' xs' | |
| where xs' = 0:xs | |
| g (y:ys) z = (ys, y+z) | |
| comb :: Int -> Int -> Integer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE TupleSections #-} | |
| module Main where | |
| import Data.Function.YaMemo (Memo, memo) | |
| import Data.Map (Map) | |
| main :: IO () | |
| main = undefined |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE FlexibleInstances #-} | |
| instances Num (a -> Maybe b) where | |
| fromInteger 1 = const Nothing | |
| a = Nothing | |
| ex = a >>= 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| テキストファイルを指定するとそのファイル名と,行番号をふった内容を印字するプログラムを作成せよ. | |
| ただし,ファイルは複数指定できるものとし,行番号は(そのファイルでの)残りの行数を表す数である. | |
| (対象ファイルがn行からなる場合,n-1から0までの番号が降順にふられる.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE EmptyDataDecls #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| {-# LANGUAGE TypeSynonymInstances #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| {-# LANGUAGE OverlappingInstances #-} | |
| {-# LANGUAGE UndecidableInstances #-} | |
| {-# LANGUAGE ScopedTypeVariables #-} | |
| module AdventCalendar2012 where |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Main where | |
| import System.Environment | |
| main :: IO () | |
| main = mapM_ numbering =<< getArgs | |
| numbering :: FilePath -> IO () | |
| numbering f = putStr . unlines . zipWith number [1..] . lines =<< readFile f | |
| number :: Int -> String -> String |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- | 式の定義 | |
| data Expr = Zero | |
| | Pred Expr | |
| | Succ Expr | |
| | Add (Expr, Expr) | |
| deriving (Show) | |
| data AExpr' = AZero | |
| | APred AExpr |