Skip to content
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

Port raindrops test-suite to support Data.Text #853

Merged
merged 1 commit into from
Oct 10, 2019

Conversation

tejasbubane
Copy link
Member

Issue: #841

Copy link
Contributor

@sshine sshine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

  • The hint that was copied from Bob should mention convert rather than responseFor.
  • The parenthesis around fromString expected will satisfy HLint. (CI fails here.)
  • Running configlet fmt . --only raindrops will ensure that README.md is updated. (CI fails here.)

The rest is optional.

import Data.Text (Text)
```

- You can now write e.g. `responseFor :: Text -> Text` and refer to `Data.Text` combinators as e.g. `T.isSuffixOf`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- You can now write e.g. `responseFor :: Text -> Text` and refer to `Data.Text` combinators as e.g. `T.isSuffixOf`.
- You can now write e.g. `convert :: Int -> Text` and refer to `Data.Text` combinators as e.g. `T.pack`.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Come to think of it, perhaps this is superfluous with the "You can then replace ..." sentence in a bullet below.

Suggested change
- You can now write e.g. `responseFor :: Text -> Text` and refer to `Data.Text` combinators as e.g. `T.isSuffixOf`.
- You can now refer to `Data.Text` combinators as e.g. `T.pack`.

Comment on lines 14 to 15
sound noise factor | n `rem` factor == 0 = Just noise
| otherwise = Nothing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that guards are moved to the second line to reduce line length:

sound noise factor
  | n `rem` factor == 0 = Just noise
  | otherwise           = Nothing

Another way to write this is:

sound noise factor = do
  guard (n `rem` factor == 0)
  pure noise

The last line is incidentally what an octogenarian would say if you play dubstep to them.

Copy link
Contributor

@sshine sshine Oct 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After having reviewed #843, I've come to think that if-then-else solutions like

sound noise factor =
  if n `rem` factor == 0
  then pure noise
  else empty

are perfectly acceptable.

Comment on lines 11 to 13
maybeSound = sound "Pling" 3 `mappend`
sound "Plang" 5 `mappend`
sound "Plong" 7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this version-control friendly,

maybeSound = sound "Pling" 3
   `mappend` sound "Plang" 5
   `mappend` sound "Plong" 7

Alternatively, use (<>), but this also looks good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this is a very cool use of the Semigroup a => Semigroup (Maybe a) instance!


import Raindrops (convert)
import Raindrops (convert)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though this is not a consistent standard in this track, or any recommended practice outside of this track, I've mostly seen that the module being tested is listed outside of alphabetical order and without indentation. Whether we should keep this convention or not is clearly debatable, but it should be outside the scope of this PR.

$ ls exercises
114
$ find . -name Tests.hs -exec ack '^import (?!Test)\S+ \(' {} \; | wc -l
100
Suggested change
import Raindrops (convert)
import Raindrops (convert)

@@ -16,7 +18,7 @@ specs = describe "convert" $ for_ cases test
test (number, expected) = it description assertion
where
description = show number
assertion = convert number `shouldBe` expected
assertion = convert number `shouldBe` (fromString expected)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI throws up about this.

Suggested change
assertion = convert number `shouldBe` (fromString expected)
assertion = convert number `shouldBe` fromString expected

Comment on lines 9 to 13
convert n = fromMaybe (T.pack $ show n) maybeSound
where
maybeSound = sound "Pling" 3 `mappend`
sound "Plang" 5 `mappend`
sound "Plong" 7
Copy link
Contributor

@sshine sshine Oct 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also avoid the maybeSound binding by writing

convert n = fromMaybe (T.pack (show n)) $
  sound "Pling" 3 <>
  sound "Plang" 5 <>
  sound "Plong" 7
  where
    sound = ...

@tejasbubane
Copy link
Member Author

@sshine Thanks 👍 I have made the changes.

Copy link
Contributor

@sshine sshine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent.

By the way, when you force push, I cannot see the difference since the last review.

When you don't, we can still squash merge the PR.

@sshine sshine merged commit 8dddba3 into exercism:master Oct 10, 2019
@petertseng
Copy link
Member

petertseng commented Oct 10, 2019

Well, "cannot" is a flexible term. There's always https://github.com/exercism/haskell/compare/b33ff3ea9c0b44398d9ea8c199af58e061bcbcd3..79a5a2b05383911d49680351a0a1212af98f8110.

And may I point out that (on the web interface), the word "force-pushed" is a link to that.

@sshine
Copy link
Contributor

sshine commented Oct 10, 2019

Wow, I didn't know that was a hyperlink.

Thanks for that.

@tejasbubane tejasbubane deleted the raindrops-text branch October 14, 2019 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants