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
-- しゅくだい exercise1.hs | |
-- ここから(だいたい)2章までの知識縛り | |
-- 中身が任意の型であること以外要求しないので型制約なし | |
null' :: [a] -> Bool | |
null' xs = if length xs == 0 then True else False | |
-- (+) を使うので Num a と制約 | |
sum' :: Num a => [a] -> a |
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
concat = (xss) -> | |
ys = [] | |
for xs in xss | |
for x in xs | |
ys.push(x) | |
ys | |
# Listモナドのつもり | |
class List | |
constructor: (@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
-- すごいHaskell読書会 in 大阪 第2回 | |
-- 練習問題 答案 @akanehara | |
import Data.Char | |
-- 演習1 | |
-- 与えられた文字列を大文字に変換する関数を書きなさい。 | |
upperCase :: String -> String | |
upperCase [] = [] |
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
var A = Array; | |
// (++) :: [a] -> [a] -> [a] | |
// | 既存の連結メソッド | |
A.prototype.concat; | |
// ------------------------------------ | |
// Monad | |
// return :: Monad m => a -> m a |
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
let foldl f z xs = | |
let rec go acc xs = | |
match xs with | |
| [] -> acc | |
| x :: xs -> go (f acc x) xs | |
in go z xs;; | |
let foldr f z xs = | |
let rec go xs = | |
match xs with |
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
def foldr[A, B](f:(A, B) => B)(z:B)(xs:List[A]):B = { | |
def go(xs:List[A]):B = xs match { | |
case Nil => z | |
case x :: rest => f(x, go(rest)) | |
} | |
go(xs) | |
} | |
def foldl[A, B](f:(A, B) => A)(z:A)(xs:List[B]):A = { | |
def go(acc:A, xs:List[B]):A = xs match { |
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 (main) where | |
main :: IO () | |
main = do | |
let fingersPermutation = permutation fingers | |
mapM_ (putStrLn . show) fingersPermutation | |
putStrLn $ show $ length fingersPermutation | |
fingers :: [Int] | |
fingers = [1..5] |
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
-- すごいHaskell読書会 in 大阪 #3 | |
-- 練習問題 | |
-- 問題1 | |
-- 次のリスト内包を **map** と **filter** で書き直してみましょう | |
-- [ x ^ 2 | x <- [1..5], odd x] | |
-- 問題2 | |
-- 標準関数 **takeWhile'** と **dropWhile'** を実装してみましょう。 |
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
-- すごいHaskell読書会 in 大阪 #3 | |
-- 練習問題 | |
-- 解答例 | |
-- 問題1 | |
-- 次のリスト内包を **map** と **filter** で書き直してみましょう | |
-- [ x ^ 2 | x <- [1..5], odd x] | |
map (^ 2) (filter odd [1..5]) |
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
-- すごいHaskell読書会 in 大阪 #4 | |
-- 第6章 モジュール | |
-- 持ち寄り練習問題 @akanehara | |
-- このスクリプトでは、英語圏でよく冗談めいて使われる | |
-- 換字式暗号ROT13(http://ja.wikipedia.org/wiki/ROT13) | |
-- の動作を確かめて遊んでいます。 | |
-- ところが、ここで使われているモジュール Toys.Rot13 | |
-- はまだ実装されていません! | |
-- testRot13 が True を返すように、Toys.Rot13 を実装 |
OlderNewer