@@ -16,9 +16,8 @@ provides an interface for converting values to
17\begin{SaveVerbatim}{showclass}
17\begin{SaveVerbatim}{showclass}
19−class Show a where {
19+class Show a where
20 show : a -> String
20 show : a -> String
23\end{SaveVerbatim}
22\end{SaveVerbatim}
24\useverb{showclass}
23\useverb{showclass}
@@ -43,10 +42,9 @@ could be defined as:
44\begin{SaveVerbatim}{shownat}
43\begin{SaveVerbatim}{shownat}
46−instance Show Nat where {
45+instance Show Nat where
47 show O = "O"
46 show O = "O"
48 show (S k) = "s" ++ show k
47 show (S k) = "s" ++ show k
51Idris> show (S (S (S O)))
49Idris> show (S (S (S O)))
52"sssO" : String
50"sssO" : String
@@ -62,14 +60,12 @@ to a \texttt{String}:
63\begin{SaveVerbatim}{showvec}
61\begin{SaveVerbatim}{showvec}
65−instance Show a => Show (Vect a n) where {
63+instance Show a => Show (Vect a n) where
66− show xs = "[" ++ show' xs ++ "]" where {
64+ show xs = "[" ++ show' xs ++ "]" where
67 show' : Show a => Vect a n -> String
65 show' : Show a => Vect a n -> String
68 show' VNil = ""
66 show' VNil = ""
69 show' (x :: VNil) = show x
67 show' (x :: VNil) = show x
70 show' (x :: xs) = show x ++ ", " ++ show' xs
68 show' (x :: xs) = show x ++ ", " ++ show' xs
74\end{SaveVerbatim}
70\end{SaveVerbatim}
75\useverb{showvec}
71\useverb{showvec}
@@ -81,10 +77,9 @@ values for equality or inequality, with instances for all of the built-in types:
82\begin{SaveVerbatim}{eqbasic}
78\begin{SaveVerbatim}{eqbasic}
84−class Eq a where {
80+class Eq a where
85 (==) : a -> a -> Bool
81 (==) : a -> a -> Bool
86 (/=) : a -> a -> Bool
82 (/=) : a -> a -> Bool
89\end{SaveVerbatim}
84\end{SaveVerbatim}
90\useverb{eqbasic}
85\useverb{eqbasic}
@@ -95,14 +90,13 @@ For example, for an instance of \texttt{Eq} for \texttt{Nat}:
96\begin{SaveVerbatim}{eqnat}
91\begin{SaveVerbatim}{eqnat}
98−instance Eq Nat where {
93+instance Eq Nat where
99 O == O = True
94 O == O = True
100 (S x) == (S y) = x == y
95 (S x) == (S y) = x == y
101 O == (S y) = False
96 O == (S y) = False
102 (S x) == O = False
97 (S x) == O = False
104 x /= y = not (x == y)
99 x /= y = not (x == y)
107\end{SaveVerbatim}
101\end{SaveVerbatim}
108\useverb{eqnat}
102\useverb{eqnat}
@@ -115,13 +109,12 @@ declaration, in terms of the other method:
116\begin{SaveVerbatim}{eqdefault}
110\begin{SaveVerbatim}{eqdefault}
118−class Eq a where {
112+class Eq a where
119 (==) : a -> a -> Bool
113 (==) : a -> a -> Bool
120 (/=) : a -> a -> Bool
114 (/=) : a -> a -> Bool
122 x /= y = not (x == y)
116 x /= y = not (x == y)
123 y == y = not (x /= y)
117 y == y = not (x /= y)
126\end{SaveVerbatim}
119\end{SaveVerbatim}
127\useverb{eqdefault}
120\useverb{eqdefault}
@@ -146,7 +139,7 @@ data Ordering = LT | EQ | GT
147\begin{SaveVerbatim}{eqord}
140\begin{SaveVerbatim}{eqord}
149−class Eq a => Ord a where {
142+class Eq a => Ord a where
150 compare : a -> a -> Ordering
143 compare : a -> a -> Ordering
152 (<) : a -> a -> Bool
145 (<) : a -> a -> Bool
@@ -155,7 +148,6 @@ class Eq a => Ord a where {
155 (>=) : a -> a -> Bool
148 (>=) : a -> a -> Bool
156 max : a -> a -> a
149 max : a -> a -> a
157 min : a -> a -> a
150 min : a -> a -> a
160\end{SaveVerbatim}
152\end{SaveVerbatim}
161\useverb{eqord}
153\useverb{eqord}
@@ -200,10 +192,9 @@ declaration. For example:
201\begin{SaveVerbatim}{monad}
193\begin{SaveVerbatim}{monad}
203−class Monad (m : Set -> Set) where {
195+class Monad (m : Set -> Set) where
204 return : a -> m a
196 return : a -> m a
205 (>>=) : m a -> (a -> m b) -> m b
197 (>>=) : m a -> (a -> m b) -> m b
208\end{SaveVerbatim}
199\end{SaveVerbatim}
209\useverb{monad}
200\useverb{monad}
@@ -225,12 +216,11 @@ We can also define an instance for \texttt{Maybe}, as follows:
226\begin{SaveVerbatim}{maybemonad}
217\begin{SaveVerbatim}{maybemonad}
228−instance Monad Maybe where {
219+instance Monad Maybe where
229 return = Just
220 return = Just
231 Nothing >>= k = Nothing
222 Nothing >>= k = Nothing
232 (Just x) >>= k = k x
223 (Just x) >>= k = k x
235\end{SaveVerbatim}
225\end{SaveVerbatim}
236\useverb{maybemonad}
226\useverb{maybemonad}
@@ -242,10 +232,9 @@ Using this we can, for example, define a function which adds two
242\begin{SaveVerbatim}{maybeadd}
232\begin{SaveVerbatim}{maybeadd}
244m_add : Maybe Int -> Maybe Int -> Maybe Int
234m_add : Maybe Int -> Maybe Int -> Maybe Int
245−m_add x y = do { x' <- x -- Extract value from x
235+m_add x y = do x' <- x -- Extract value from x
246− y' <- y -- Extract value from y
236+ y' <- y -- Extract value from y
247− return (x' + y') -- Add them
237+ return (x' + y') -- Add them
250\end{SaveVerbatim}
239\end{SaveVerbatim}
251\useverb{maybeadd}
240\useverb{maybeadd}
@@ -273,10 +262,9 @@ general, and applies to anything which is an instance of \texttt{MonadPlus}:
274\begin{SaveVerbatim}{monadplus}
263\begin{SaveVerbatim}{monadplus}
276−class Monad m => MonadPlus (m : Set -> Set) where {
265+class Monad m => MonadPlus (m : Set -> Set) where
277 mplus : m a -> m a -> m a
266 mplus : m a -> m a -> m a
278 mzero : m a
267 mzero : m a
281\end{SaveVerbatim}
269\end{SaveVerbatim}
282\useverb{monadplus}
270\useverb{monadplus}