Created
June 17, 2013 11:10
-
-
Save chomado/5796178 to your computer and use it in GitHub Desktop.
--safetail :: [a] -> [a]
-- tail(cdr)のように振る舞うが、違いは、空リストを与えた時に空リストを返すようにすること。
-- 実装方法は、それぞれ、a. 条件式、 b. ガード付きの等式、 c. パターンマッチ でやること。
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
-- a. 条件式 | |
safetail_A :: [a] -> [a] | |
safetail_A xs = if null xs then [] else tail xs | |
-- b. ガード付きの等式 | |
safetail_B :: [a] -> [a] | |
safetail_B xs | null xs = [] | |
| otherwise = tail xs | |
-- c. パターンマッチ | |
safetail_C :: [a] -> [a] | |
safetail_C [] = [] | |
safetail_C xs = tail xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment