This file contains 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
;; 第1回 Scheme コードバトン | |
;; | |
;; ■ これは何か? | |
;; Scheme のコードをバトンのように回していき面白い物ができあがるのを楽しむ遊びです。 | |
;; 次回 Shibuya.lisp で成果を発表します。 | |
;; Scheme 初心者のコードを書くきっかけに、中級者には他人のコードを読む機会になればと思います。 | |
;; | |
;; ■ 2 つのルール | |
;; | |
;; (1)自分がこれだと思える変更をコードに加えて2日以内に次の人にまわしてください。 |
This file contains 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
#!/usr/local/bin/gosh | |
;; 第1回 Scheme コードバトン | |
;; | |
;; ■ これは何か? | |
;; Scheme のコードをバトンのように回していき面白い物ができあがるのを楽しむ遊びです。 | |
;; 次回 Shibuya.lisp で成果を発表します。 | |
;; Scheme 初心者のコードを書くきっかけに、中級者には他人のコードを読む機会になればと思います。 | |
;; | |
;; ■ 2 つのルール | |
;; |
This file contains 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 GFizzBuzz (gFizzBuzz) where | |
import Data.List | |
gFizzBuzz :: (Int,Int) -- range | |
-> [(Int,String)] -- spec of fizzbuzz | |
-> [String] -- generic FizzBuzz strings | |
gFizzBuzz r = narrow r . zipWith (#) [0..] . map concat . transpose . map gfizzs | |
This file contains 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 | |
deriving (Show,Read) | |
-- | Redex(簡約可能式)を数える. | |
countRedex :: Expr -> Int | |
countRedex Zero = 0 | |
countRedex (Succ t) = case t of |
This file contains 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 | |
deriving (Show) | |
-- | 位置情報付き式 | |
data AExpr' = AZero | |
| APred AExpr | |
| ASucc AExpr |
This file contains 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 |
This file contains 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 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 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 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 |
OlderNewer