Skip to content

Instantly share code, notes, and snippets.

@khibino
Created May 18, 2017 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khibino/399ce6a2f5ea2620117e5b123c678a50 to your computer and use it in GitHub Desktop.
Save khibino/399ce6a2f5ea2620117e5b123c678a50 to your computer and use it in GitHub Desktop.
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