Skip to content

Instantly share code, notes, and snippets.

@dontdieych
Forked from honki12345/ex1.hs
Last active September 26, 2025 08:36
Show Gist options
  • Select an option

  • Save dontdieych/ebe9d4f247d50a03c7f56ecf39aaaf39 to your computer and use it in GitHub Desktop.

Select an option

Save dontdieych/ebe9d4f247d50a03c7f56ecf39aaaf39 to your computer and use it in GitHub Desktop.
ex1
-- Q. 리스트가 빈 리스트([])인지, 또는 첫 번째 요소가 빈 리스트인지([[]], ['a','b']]와 같은)를 확인하는 표현식을 작성하세요.
-- hasOnlyOneElement t = null t || null (head t)
hasOnlyOneElement :: [[a]] -> Bool
hasOnlyOneElement [] = True
hasOnlyOneElement [[]] = True
hasOnlyOneElement _ = False
-- Q. 다른 리스트 안에 주어진 두 리스트를 연결하는 표현식을 작성하세요. 예를 들어, ["abc","de"]에 대해 "abcde"를 반환해야 합니다.
-- concatTwoElement t = head t ++ head (tail t)
concatTwoElement :: [[a]] -> [[a]] -> [a]
concatTwoElement [] [] = []
concatTwoElement [xs] [ys] = xs <> ys
-- Q. 리스트가 단 하나의 요소만 가지고 있는지 확인하는 표현식을 작성하세요. ['a']에 대해서는 True를, []나 ['a','b']에 대해서는 False를 반환해야 합니다.
-- hasOneElement t = not (null t) && null (tail t)
hasOneElement :: [a] -> Bool
hasOneElement [] = False
hasOneElement (x:[]) = True
hasOneElement _ = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment