Created
May 18, 2017 02:33
-
-
Save khibino/399ce6a2f5ea2620117e5b123c678a50 to your computer and use it in GitHub Desktop.
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
take' :: Int -> [a] -> [a] | |
take' n _ | |
| n <= 0 = [] | |
take' _ [] = [] | |
take' n (x:xs) = x : take' (n - 1) xs -- 先に整数値で場合分け, トップレベルで pattern match | |
take'2 n xxs | |
| n <= 0 = [] | |
| otherwise = case xxs of | |
[] -> [] | |
x:xs -> x : take'2 (n - 1) xs -- 先に整数値で場合分け, case で pattern match | |
take'3 _ [] = [] | |
take'3 n (x:xs) | |
| n <= 0 = [] | |
| otherwise = x : take'3 (n - 1) xs -- 先にリストで場合分け, トップレベルで pattern match | |
take'4 :: Int -> [a] -> [a] | |
take'4 n xxs = case xxs of | |
[] -> [] | |
_:_ | n <= 0 -> [] | |
x:xs -> x : take'4 (n - 1) xs -- 先にリストで場合分け, caseで pattern match |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment