Skip to content

Commit

Permalink
* Added the solutions of 2.1-5.
Browse files Browse the repository at this point in the history
  • Loading branch information
Seungcheol Jung committed Mar 11, 2010
1 parent 19cfcf7 commit 91fca9f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
47 changes: 47 additions & 0 deletions ch02.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
\chapter{\Large{First Steps}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\exercise{2.1}

\begin{lstlisting}[language=Haskell,escapeinside=~~]
(2 ^ 3) * 4
(2 * 3) + (4 * 5)
2 + (3 * (4 ^ 5))
\end{lstlisting}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\exercise{2.2}

(생략)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\exercise{2.3}

주어진 스크립트에는 다음 세가지 문제점이 있다.
\begin{itemize}
\item 함수 이름이 소문자로 시작되지 않는다.
\item 함수를 인자 사이에서 쓰려면 따옴표(\texttt{'})가 아닌
역따옴표(\texttt{`})로 묶어야 한다.
\item \texttt{where} 다음에 오는 문장의 들여쓰기가 일치하지 않는다.
\end{itemize}

수정된 스크립트는 다음과 같다.

\haskell{./src/ch02-ex03.hs}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\exercise{2.4}

\haskell{./src/ch02-ex04.hs}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\exercise{2.5}

\haskell{./src/ch02-ex05.hs}


%%% Local Variables:
%%% mode: latex
%%% TeX-master: "master"
%%% End:
1 change: 1 addition & 0 deletions master.tex
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
\maketitle
\tableofcontents
\input{ch01}
\input{ch02}

\end{document}

Expand Down
4 changes: 4 additions & 0 deletions src/ch02-ex03.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
n = a `div` length xs
where
a = 10
xs = [1,2,3,4,5]
8 changes: 8 additions & 0 deletions src/ch02-ex04.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
last1 :: [a] -> a
last1 xs = head (reverse xs)

last2 :: [a] -> a
last2 xs = xs !! (length xs - 1)

last3 :: [a] -> a
last3 xs = head (drop (length xs - 1) xs)
5 changes: 5 additions & 0 deletions src/ch02-ex05.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
init1 :: [a] -> [a]
init1 xs = reverse (tail (reverse xs))

init2 :: [a] -> [a]
init2 xs = take (length xs - 1) xs

0 comments on commit 91fca9f

Please sign in to comment.