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
| public async Task<Message> Post([FromBody]Message message) | |
| { | |
| if (message.Type == "Message") | |
| { | |
| // calculate something for us to return | |
| int length = (message.Text ?? string.Empty).Length; | |
| // return our reply to the user | |
| return message.CreateReplyMessage($"You sent {length} characters"); | |
| } |
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
| -- fact 5 | |
| -- → 5 * 4 * 3 * 2 * 1 | |
| fact :: Int -> Int | |
| fact 0 = 1 | |
| fact x = x * fact (x - 1) | |
| main :: IO() | |
| main = do | |
| print $ fact 5 -- 120 |
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 Debug.Trace | |
| fib :: Num a => [a] | |
| fib = 0:1:(trace ("fib [" ++ show fib ++ "] + tail fib [" ++ show (tail fib) ++ "]") | |
| (zipWith (+) fib (tail fib))) | |
| main = do | |
| traceIO $ show $ take 10 fib |
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
| fib :: Num a => [a] | |
| fib = 0:1:zipWith (+) fib (tail fib) |
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 Debug.Trace | |
| -- trace (表示させたい文字列) (処理return) | |
| f x = trace ("x = " ++ show x) x + 1 | |
| main = do | |
| traceIO $ show $ f 5 | |
| -- x = 5 | |
| -- 6 |
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
| -- フィボナッチ数列生成のためのテスト関数 | |
| fibo :: (Int -> Int) -> Int -> [Int] | |
| fibo func n = [func x| x <- [0..n]] | |
| -- パターンマッチで実装 | |
| fib :: Int -> Int | |
| fib 0 = 0 | |
| fib 1 = 1 | |
| fib n = fib (n-1) + fib (n-2) |
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
| insert :: Ord a => a -> [a] -> [a] | |
| insert x [] = [x] | |
| insert x (y : ys) | |
| | x <= y = x:y:ys | |
| | otherwise = y: insert x ys | |
| isort :: Ord a => [a] -> [a] | |
| isort [] = [] | |
| isort (x:xs) = insert x $ isort 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
| qsort :: Ord a => [a] -> [a] | |
| qsort [] = [] | |
| qsort (pivot:xs) = qsort smaller ++ [pivot] ++ qsort larger | |
| where | |
| smaller = [x | x <- xs, x < pivot] | |
| larger = [x | x <- xs, x >= pivot] | |
| main = do | |
| print $ qsort [4, 6, 9, 8, 3, 5, 1, 7, 2] | |
| -- [1,2,3,4,5,6,7,8,9] |
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.Char | |
| -- 文字c を シフト数n だけずらす関数 | |
| shift :: Int -> Char -> Char | |
| shift n c | |
| | isLower c = chr $ ord 'a' + ((ord c - ord 'a') + n) `mod` 26 | |
| | isUpper c = chr $ ord 'A' + ((ord c - ord 'A') + n) `mod` 26 | |
| | otherwise = c | |
| --シーザー暗号化する関数 |
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
| length' :: [a] -> Int | |
| length' [] = 0 | |
| length' (x:xs) = 1 + length' xs | |
| ---------- | |
| take' :: Int -> [a] -> [a] | |
| take' _ [] = [] | |
| take' 0 _ = [] | |
| take' n (x:xs) = x : take' (n-1) xs |