Skip to content

Commit c9f87a0

Browse files
authored
Make all exercises not compile to start (#25)
1 parent 905aa5a commit c9f87a0

25 files changed

+81
-61
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Within the [exercises directory](https://github.com/MondayMorningHaskell/haskell
3737

3838
This will run the [`Types1`](https://github.com/MondayMorningHaskell/haskellings/blob/master/exercises/basics/Types1.hs) exercise.
3939

40-
Initially, exercises will not compile. You'll want to open the file, read the information at the top, and then fill in the code as indicated by the `TODO` comments.
40+
Initially, exercises will not compile. You'll want to open the file, read the information at the top, and then fill in the code as indicated by the `TODO` comments. You'll usually be replacing the question marks `???` with your function implementations and type declarations.
4141

4242
You can re-run the exercise, and the output will let you know when you're done!
4343

@@ -48,6 +48,26 @@ If you're stuck, each exercise also has a hint you can see by running `haskellin
4848
Fill in appropriate type signatures for the expressions at the bottom.
4949
```
5050

51+
Sometimes you might want to compile and run code you've written for one function without filling in the rest. When this happens, you can usually replace the question marks `???` for function implementations with the phrase `undefined`. Using `undefined` lets your code compile, though that particular function won't run:
52+
53+
```haskell
54+
-- BEFORE:
55+
subtract7 :: Int -> Int
56+
subtract7 = ???
57+
58+
multiplyBy7 :: Int -> Int
59+
multiplyBy7 = ???
60+
61+
-- AFTER:
62+
subtract7 :: Int -> Int
63+
subtract7 x = x - 7
64+
65+
multiplyBy7 :: Int -> Int
66+
multiplyBy7 = undefined
67+
```
68+
69+
For example, after making the above change, you'll be able to run the tests for the `subtract7` function. You'll still see errors while running the tests for `multiplyBy7`, but they will compile. Sometimes the implementation will start as `undefined` rather than `???`, in which case it's still your job to replace it!
70+
5171
## Using the Watcher
5272

5373
The simplest way to ensure that you're doing exercises _in order_ is to use the Watcher. You can invoke this with the command `haskellings watch`.

exercises/functions/Functions2.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ Here are a few examples:
4040
-- Add the heads of the two inputs together. Return this as the first element
4141
-- of the tuple. Then you should also return the tail of each list.
4242
addHeads :: ([Int], [Int]) -> (Int, [Int], [Int])
43-
addHeads = undefined
43+
addHeads = ???
4444

4545
-- Produce a new tuple containing the three *second* elements of each of
4646
-- the input tuples.
4747
takeSeconds :: (Int, Int) -> (Int, Int) -> (Int, Int) -> (Int, Int, Int)
48-
takeSeconds = undefined
48+
takeSeconds = ???
4949

5050
-- Capitalize each of the three characters
5151
capitalize :: (Char, Char, Char) -> (Char, Char, Char)
52-
capitalize = undefined
52+
capitalize = ???
5353

5454
-- Testing Code, You can ignore this:
5555
main :: IO ()

exercises/functions/Functions3.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ multiplyBy3Add5 = multiplyBy3AndAdd 5
3030
-- Then multiply the second elements together as well.
3131
-- Add the results.
3232
multiplyAndAdd :: (Int, Int) -> (Int, Int) -> Int
33-
multiplyAndAdd = undefined
33+
multiplyAndAdd = ???
3434

3535
-- Take a tuple of two Ints.
3636
-- Multiply the first value by 3 and the second by 4. Then add the results.

exercises/functions/Functions5.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ the front of a list:
4141
-- This should take any boolean value and return True!
4242
-- (There are two easy ways to do this, try both!)
4343
trueSink :: Bool -> Bool
44-
trueSink = undefined
44+
trueSink = ???
4545

4646
-- This should take any boolean value and return False!
4747
falseSink :: Bool -> Bool
48-
falseSink = undefined
48+
falseSink = ???
4949

5050
-- Return True if and only if all three inputs are true.
5151
tripleAnd :: Bool -> Bool -> Bool -> Bool
52-
tripleAnd = undefined
52+
tripleAnd = ???
5353

5454
-- Take two lists. Remove the first element from each list and add them together.
5555
-- The first output should be like the first list except with this new sum at the
5656
-- start instead of the original value. The second output should be the tail of the
5757
-- original second input.
5858
-- addToFirstList [1, 2] [9, 8] = ([10, 2], [8])
5959
addToFirstList :: [Int] -> [Int] -> ([Int], [Int])
60-
addToFirstList = undefined
60+
addToFirstList = ???
6161

6262
-- Testing Code
6363
main :: IO ()

exercises/functions/Functions6.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ doubleList xs = map double xs
3636

3737
-- Flip the boolean value of each input
3838
flipBools :: [Bool] -> [Bool]
39-
flipBools input = undefined
39+
flipBools input = ???
4040

4141
-- Uppercase all the letters in this word!
4242
capitalizeWord :: String -> String
43-
capitalizeWord input = undefined
43+
capitalizeWord input = ???
4444

4545
-- TODO: Create your own higher order function, doubleAndApply.
4646
-- The input function should take a single integer

exercises/lists/Lists1.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ foldr min 9999 [5, 7, 2, 9, 1]
6060
-- higher order helper functions instead!
6161

6262
addMod3Is2 :: [Int] -> [Int]
63-
addMod3Is2 = undefined
63+
addMod3Is2 = ???
6464

6565
sumList :: [Int] -> Int
66-
sumList = undefined
66+
sumList = ???
6767

6868
-- Return true if every element is 'True'!
6969
-- (The empty list should return 'True'!)
7070
allTrue :: [Bool] -> Bool
71-
allTrue bs = undefined
71+
allTrue bs = ???
7272

7373
main :: IO ()
7474
main = defaultMain $ testGroup "Lists1" $

exercises/lists/Lists2.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ cycle [1, 2, 3, 4] -- < [1, 2, 3, 4, 1, 2, 3, 4, 1 ...]
4949
-- Given a particular number, give a list of the numbers starting
5050
-- there and counting down by 5 until you get to 0.
5151
countdownBy5 :: Word -> [Word]
52-
countdownBy5 = undefined
52+
countdownBy5 = ???
5353

5454
-- Given a particular Int, create a list with 100 copies of it.
5555
give100 :: Int -> [Int]
56-
give100 = undefined
56+
give100 = ???
5757

5858
main :: IO ()
5959
main = defaultMain $ testGroup "Lists2" $

exercises/lists/Lists3.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ shortWords = ["HELLO", "BYE", "CIAO"]
5050

5151
-- Implement addMod3Is2, except now use a list comprehension.
5252
addMod3Is2 :: [Int] -> [Int]
53-
addMod3Is2 = undefined
53+
addMod3Is2 = ???
5454

5555
-- Take every pairwise product of the numbers, as long as their
5656
-- sum is less than 30.
5757
smallPairwiseProducts :: [Int] -> [Int] -> [Int]
58-
smallPairwiseProducts = undefined
58+
smallPairwiseProducts = ???
5959

6060
main :: IO ()
6161
main = defaultMain $ testGroup "Lists3" $

exercises/lists/Lists4.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ zip [1, 2, 3] ["Hi", "Bye"] = [(1, "Hi"), (2, "Bye")]
2727
-- return tuples containing the sum, product, and difference of each pair.
2828
-- sumProductDifference [4, 3] [1, 2] = [(5, 4, 3), (5, 6, 1)]
2929
sumProductDifference :: [Int] -> [Int] -> [(Int, Int, Int)]
30-
sumProductDifference = undefined
30+
sumProductDifference = ???
3131

3232
-- Given a list of strings, make a new list where each String has been
3333
-- appended with its index within the list.
3434
-- addIndices ["Hello", "Bye"] = ["Hello0", "Bye1"]
3535
addIndices :: [String] -> [String]
36-
addIndices = undefined
36+
addIndices = ???
3737

3838
main :: IO ()
3939
main = defaultMain $ testGroup "Lists4" $

exercises/monads/Applicatives.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ safeSquareRoot x = if x < 0 then Nothing else Just (sqrt x)
6565
-- Return the sum of the square roots of the two inputs, using
6666
-- 'safeSquareRoot' to check for negatives.
6767
sumOfSquareRoots :: Double -> Double -> Maybe Double
68-
sumOfSquareRoots = undefined
68+
sumOfSquareRoots = ???
6969

7070
-- Generate all combinations of sums between the first list and the second list.
7171
-- (avoid using a list comprehension)
7272
generateSums :: [Int] -> [Int] -> [Int]
73-
generateSums = undefined
73+
generateSums = ???
7474

7575
-- Given a list of operations and two lists, generate all combinations of
7676
-- those operations with each pair of numbers from the two lists.
7777
-- generateAllResults [(+), (*)] [1, 2] [3, 4] -> [4, 5, 5, 6, 3, 4, 6, 8]
7878
generateAllResults :: [Int -> Int -> Int] -> [Int] -> [Int] -> [Int]
79-
generateAllResults = undefined
79+
generateAllResults = ???
8080

8181
main :: IO ()
8282
main = defaultMain $ testGroup "Applicatives" $

0 commit comments

Comments
 (0)