Skip to content

Instantly share code, notes, and snippets.

@chomado
Created June 17, 2013 11:10
Show Gist options
  • Save chomado/5796178 to your computer and use it in GitHub Desktop.
Save chomado/5796178 to your computer and use it in GitHub Desktop.
--safetail :: [a] -> [a] -- tail(cdr)のように振る舞うが、違いは、空リストを与えた時に空リストを返すようにすること。 -- 実装方法は、それぞれ、a. 条件式、 b. ガード付きの等式、 c. パターンマッチ でやること。
-- 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