-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port raindrops test-suite to support Data.Text
Issue: #841
- Loading branch information
1 parent
ef488d3
commit b33ff3e
Showing
5 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## Hints | ||
|
||
You need to implement the `convert` function that returns number converted to | ||
raindrop sound. You can use the provided signature if you are unsure | ||
about the types, but don't let it restrict your creativity: | ||
|
||
```haskell | ||
convert :: Int -> String | ||
``` | ||
|
||
This exercise works with textual data. For historical reasons, Haskell's | ||
`String` type is synonymous with `[Char]`, a list of characters. For more | ||
efficient handling of textual data, the `Text` type can be used. | ||
|
||
As an optional extension to this exercise, you can | ||
|
||
- Read about [string types](https://haskell-lang.org/tutorial/string-types) in Haskell. | ||
- Add `- text` to your list of dependencies in package.yaml. | ||
- Import `Data.Text` in [the following way](https://hackernoon.com/4-steps-to-a-better-imports-list-in-haskell-43a3d868273c): | ||
|
||
```haskell | ||
import qualified Data.Text as T | ||
import Data.Text (Text) | ||
``` | ||
|
||
- You can now write e.g. `convert :: Int -> Text` and refer to `Data.Text` combinators as e.g. `T.pack`. | ||
- Look up the documentation for [`Data.Text`](https://hackage.haskell.org/package/text-1.2.3.1/docs/Data-Text.html), | ||
- You can then replace all occurrences of `String` with `Text` in Raindrops.hs: | ||
|
||
```haskell | ||
convert :: Int -> Text | ||
``` | ||
|
||
This part is entirely optional. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: raindrops | ||
|
||
dependencies: | ||
- base | ||
- text | ||
|
||
library: | ||
exposed-modules: Raindrops | ||
source-dirs: src | ||
|
||
tests: | ||
test: | ||
main: Tests.hs | ||
source-dirs: test | ||
dependencies: | ||
- raindrops | ||
- hspec |
16 changes: 16 additions & 0 deletions
16
exercises/raindrops/examples/success-text/src/Raindrops.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Raindrops (convert) where | ||
|
||
import Data.Maybe (fromMaybe) | ||
import qualified Data.Text as T | ||
import Data.Text (Text) | ||
|
||
convert :: Int -> Text | ||
convert n = fromMaybe (T.pack $ show n) $ | ||
sound "Pling" 3 <> | ||
sound "Plang" 5 <> | ||
sound "Plong" 7 | ||
where | ||
sound noise factor | ||
| n `rem` factor == 0 = Just noise | ||
| otherwise = Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: raindrops | ||
version: 1.1.0.5 | ||
version: 1.1.0.6 | ||
|
||
dependencies: | ||
- base | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters