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

pangram 1.4.1.10: Add test case: determine pangram lazily #795

Merged
merged 4 commits into from
Dec 17, 2018
Merged

pangram 1.4.1.10: Add test case: determine pangram lazily #795

merged 4 commits into from
Dec 17, 2018

Conversation

sshine
Copy link
Contributor

@sshine sshine commented Dec 14, 2018

Fail if the input stream was touched beyond the first occurrence of each letter.

Many standard solutions achieve this property without much effort, and some don't.

This test case notifies the student that a more optimal solution is within reach.

It is commented out by default:

While success-standard passes this test, and a String-based
fail-too-eager example fails as expected, success-text cannot easily
succeed, even if is changed into using Data.Text.Lazy:

One can write a Data.Text.Lazy as LT-specific test:

describe "isPangram" $ do
  it "is lazy" $
    isPangram (LT.fromChunks ["a...z", undefined]) `shouldBe` True

But when the input comes via fromString :: IsString s => String -> s,
the implementation has little control of the chunking. A failed attempt
to circumvent this,

newtype ChunkyLazyText = ChunkyLazyText LT.Text

instance IsString ChunkyLazyText where
  fromString = ChunkyLazyText . LT.fromChunks . map (T.pack . return)

still causes the T.pack invocation on [undefined].

And as @bobdalgleish pointed out in this StackOverflow comment,
I'd actually end up testing fromString. Since "laziness" doesn't mean
the same thing for String as it does for Data.Text.Lazy because
chunking works differently, the reliable alternative is to write tests
for each implementation.

Or, in this case, let string-type specific tests remain commented out.

Fail if the input stream was touched beyond the first occurrence of each letter.

Many standard solutions achieve this property without much effort, and some don't.

This test case notifies the student that a more optimal solution is within reach.
While `success-standard` passes this test, and a `String`-based
`fail-too-eager` example fails as expected, `success-text` cannot easily
succeed, even if is changed into using `Data.Text.Lazy`:

One can write a `Data.Text.Lazy as LT`-specific test:

    describe "isPangram" $ do
      it "is lazy" $
        isPangram (LT.fromChunks ["a...z", undefined]) `shouldBe` True

But when the input comes via `fromString :: IsString s => String -> s`,
the implementation has little control of the chunking. A failed attempt
to circumvent this,

    newtype ChunkyLazyText = ChunkyLazyText LT.Text

    instance IsString ChunkyLazyText where
      fromString = ChunkyLazyText . LT.fromChunks . map (T.pack . return)

still causes the `T.pack` invocation on `[undefined]`.

And as @bobdalgleish pointed out in [this StackOverflow question][SO],
I'd actually end up testing `fromString`. Since "laziness" doesn't mean
the same thing for `String` as it does for `Data.Text.Lazy` because
chunking works differently, the reliable alternative is to write tests
for each implementation.

Or, in this case, let string-type specific tests remain commented out.

[SO]: https://stackoverflow.com/questions/53784627/testing-laziness-of-isstring-s-s-bool-function
Copy link
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

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

Interesting observations about Text-based implementations.

@sshine
Copy link
Contributor Author

sshine commented Dec 15, 2018

Yes. It's a property of very granulated strings. The main reason to discourage lazy Text appears to have to do with I/O.

Also it's a rabbit hole.

@sshine sshine merged commit 0df3823 into exercism:master Dec 17, 2018
@sshine sshine mentioned this pull request Feb 26, 2019
2 tasks
sshine added a commit that referenced this pull request Mar 8, 2019
As part of [The Track Anatomy Project][1], the Haskell core track is
restructured in #798 using @F3PiX'es multi-stage framework referred to
as "The Track Tool".

Since The Track Tool is still under development, it isn't documented
yet. But the execution of the first step can be viewed for other
languages, e.g. exercism/javascript#590.

---

Proposal:

 - Switch "Bob" and "Pangram".

   They're both about handling textual data.

   Pangram has fewer gotchas, is quicker done, has more variations among
   its alternative solutions, and doesn't lend itself as well to `Data.Text`.
   (See #795.) Bob often involves more refactoring, has more learning
   objectives and has the extra "You could do it with Data.Text, too!" part.

   This way people don't try to solve Pangram with Data.Text which is possible
   but not ideal without mono-traversable, and they get an exercise more under
   their belt before being thrown into a lot of refactoring.

 - Switch "Nucleotide Count" and "Sum of Multiples".

   Eventually I think we should delete "Sum of Multiples" and "Grains" (see #761).

   But since The Track Tool does not address removal yet, I want to make
   "Nucleotide Count" come immediately after "RNA Transcription", since
   they're both thematically related and Nucleotide Count uses Either
   while RNA Transcription uses Maybe for monadic error handling, so they
   practice the same thing in progressive difficulty.

The proposed track reordering looks like:

1. hello-world
2. leap
3. space-age
4. **pangram**
5. **bob**
6. collatz-conjecture
7. rna-transcription
8. **nucleotide-count**
9. sum-of-multiples
10. grains

[1]: https://exercism.io/blog/track-anatomy-project
@sshine sshine deleted the pangram-lazy-test branch March 12, 2019 10:33
ErikSchierboom added a commit to ErikSchierboom/haskell that referenced this pull request Jan 27, 2021
* [Docs] Move implementing-a-concept-exercise.md to reference folder
* [Docs] Move reference documents to docs folder
* [Docs] Update to student-facing docs
* [Docs] Add new issue template

Co-Authored-By: Jeremy Walker <[email protected]>
Co-Authored-By: Victor Goff <[email protected]>
Co-authored-by: Sascha Mann <[email protected]>
ErikSchierboom added a commit to ErikSchierboom/haskell that referenced this pull request Jan 28, 2021
* [Docs] Move implementing-a-concept-exercise.md to reference folder
* [Docs] Move reference documents to docs folder
* [Docs] Update to student-facing docs
* [Docs] Add new issue template

Co-Authored-By: Jeremy Walker <[email protected]>
Co-Authored-By: Victor Goff <[email protected]>
Co-authored-by: Sascha Mann <[email protected]>
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.

2 participants