Skip to content

Commit a4aeb17

Browse files
authored
added a new list exercise to 3.iv (#87)
1 parent 3e542f3 commit a4aeb17

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/Solutions/DataTypes.idr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ filterList f Nil = Nil
190190
filterList f (x :: xs) =
191191
if f x then x :: filterList f xs else filterList f xs
192192

193+
(++) : List a -> List a -> List a
194+
(++) Nil ys = ys
195+
(++) (x :: xs) ys = x :: (Solutions.DataTypes.(++) xs ys)
196+
193197
headMaybe : List a -> Maybe a
194198
headMaybe Nil = Nothing
195199
headMaybe (x :: _) = Just x

src/Tutorial/DataTypes.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,14 @@ signature are treated as type parameters.
12121212
total
12131213
filterList : (a -> Bool) -> List a -> List a
12141214
1215+
-- re-implement list concatenation (++) such that e.g. (++) [1, 2] [3, 4] = [1, 2, 3, 4]
1216+
-- note that because this function conflicts with the standard
1217+
-- Prelude.List.(++), if you use it then you will need to prefix it with
1218+
-- the name of your module, like DataTypes.(++) or Ch3.(++). alternatively
1219+
-- you could simply call the function something unique like myListConcat or concat'
1220+
total
1221+
(++) : List a -> List a -> List a
1222+
12151223
-- return the first value of a list, if it is non-empty
12161224
total
12171225
headMaybe : List a -> Maybe a

0 commit comments

Comments
 (0)