-
-
Notifications
You must be signed in to change notification settings - Fork 195
Add explicit args to Exercises - Part 1 #504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add explicit args to Exercises - Part 1 #504
Conversation
Is desirable that, after a few exercises, the student start developing point-free skills. Certainly the people solving the last exercises have a at least a basic competence at eta-reduction. I thought about the explicit arguments for later exercises more as documentation to help the students identify what each argument is, and maybe also as an additional exposure to idiomatic argument naming, which is usually something people slowly learn reading the function's implementations in Hackage. Following the same reasoning, we also have the pattern-matching, which isn't possible without changing some explicit arguments, and that is also a must-learn syntax. I'm unsure about what is the best for the track, so I'll copy the other maintainers to see what they think about it. @exercism/haskell |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a few comments about some naming choices, but avoided repeating then in similar cases. Remember that it is just my opinion.
I'll approve and leave for you to decide if you want to change anything. When you decide it is ready to merge, please tell me.
@@ -1,7 +1,7 @@ | |||
module Atbash (decode, encode) where | |||
|
|||
decode :: String -> String | |||
decode = error "You need to implement this function." | |||
decode phrase = error "You need to implement this function." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would normally go for xs
for strings, or maybe cipherText
for more something more descriptive. I'm not sure.
Edit: phrase
is also OK, of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also prefer following the convention (f
or g
for functions, xs
ys
for generic lists, etc.) and I'm happy to change.
The reason I choose phrase
here instead, was to match the test suite, believing that it would be easier for the student to understand the test cases.
I followed this same approach for other exercises, trying to match the test suite terms whenever possible, but I'm happy to change them as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please feel free to keep or to change the names you chose.
|
||
empty :: BST a | ||
empty = error "You need to implement this function." | ||
|
||
fromList :: Ord a => [a] -> BST a | ||
fromList = error "You need to implement this function." | ||
fromList elems = error "You need to implement this function." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a list of a completely unknown type, the tradition is to use xs
, considering that there is no possible descriptive name.
|
||
singleton :: a -> BST a | ||
singleton = error "You need to implement this function." | ||
singleton elem = error "You need to implement this function." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single unknown element usually is x
.
@@ -3,4 +3,4 @@ module Connect (Mark(..), winner) where | |||
data Mark = Cross | Nought deriving (Eq, Show) | |||
|
|||
winner :: [String] -> Maybe Mark | |||
winner = error "You need to implement this function." | |||
winner board = error "You need to implement this function." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
board
is certainly more descriptive than xss
. 👍
@@ -1,4 +1,4 @@ | |||
module CryptoSquare (encode) where | |||
|
|||
encode :: String -> String | |||
encode = error "You need to implement this function." | |||
encode input = error "You need to implement this function." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, input
doesn't add anything. I would normally go with xs
, or something more descriptive, like plainText
.
@@ -19,40 +19,40 @@ import Prelude hiding (null) | |||
data CustomSet a = Dummy deriving (Eq, Show) | |||
|
|||
delete :: a -> CustomSet a -> CustomSet a | |||
delete = error "You need to implement this function." | |||
delete elem set = error "You need to implement this function." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never thought about how to name sets...set
seems ok. 👍
@@ -1,10 +1,10 @@ | |||
module Squares (difference, squareOfSums, sumOfSquares) where | |||
|
|||
difference :: Integral a => a -> a | |||
difference = error "You need to implement this function." | |||
difference n = error "You need to implement this function." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n
fits perfectly!
I'm happy with the changes now 👍 |
Thanks! 😄 Just one final question before merging. Would you like to squash the commits that affect the same exercise together, to create a more clean history? |
5e7c377
to
3223c18
Compare
done 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consequently, wouldn't eta-conversion also be part of the concepts
My past opinion at #459 (comment)
summary: I support explicit naming to make clear the meaning of each arg.
I'm certainly happy to be convinced otherwise.
I hope students will not be afraid to eta-reduce when appropriate for the solution.
@@ -1,4 +1,4 @@ | |||
module CryptoSquare (encode) where | |||
|
|||
encode :: String -> String | |||
encode = error "You need to implement this function." | |||
encode xs = error "You need to implement this function." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry that I know I'm contradicting #504 (comment) here, but it seemed a bit inconsistent here to use xs
but phrase
in atbash-cipher
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree!
@@ -1,4 +1,4 @@ | |||
module Series (largestProduct) where | |||
|
|||
largestProduct :: Int -> String -> Maybe Integer | |||
largestProduct = error "You need to implement this function." | |||
largestProduct series digits = error "You need to implement this function." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
series
seems confusing to me since an integer is not really a series. It is the size of the seires we are considering within the digits. I would think either size
or span
.
Part of #473
Perhaps the next PRs will be smaller, so they can be reviewed easier.
I was thinking about some of the exercises covered in this PR and how much more complex they are in comparison to the first 10 - 15 available exercises (the ones I've completed so far).
Once the student get there, he will have crossed a few Haskell / FP concepts, which is one of the goals of this Track.
Consequently, wouldn't eta-conversion also be part of the concepts he should familiarize with? Therefore, I believe that, starting from a complex enough exercise, keeping the function arguments out would create a better learning experience.