Closed aaronallen8455 closed 1 year ago
Thanks for your suggestions! I'm definitely open to different/better examples. The current ones are definitely very algorithmic.
Your examples are a bit longer than the current ones -- the two mergesort implementations are 22 and 24 lines, whereas yours are 36 and 34 lines. On my machine they still fit on the screen, though. I think the shorter the examples, the better.
I like your first example (the ADT domain modelling), though I would maybe replace putStrLn $ T.unpack
with T.putStrLn
after importing Data.Text.IO
as well.
For your second example, while it is a nice example of deriving strategies and a custom, interesting reduction operator, it's somewhat sad that we need 3 language extensions as well as GHC Generics, all of which are not in beginner Haskell tutorials, nor necessarily in common simple Haskell code. In short, I suspect it looks daunting to the novice Haskell programmer, where the mergesort examples, while maybe algorithmically more complex, at least use very simple Haskell.
What do you think?
Glad to hear that your open to the suggestion! I think we're mostly in agreement regarding the 2 draft examples.
Your examples are a bit longer than the current ones -- the two mergesort implementations are 22 and 24 lines, whereas yours are 36 and 34 lines. On my machine they still fit on the screen, though. I think the shorter the examples, the better.
I definitely share your concerns about the line count (Funny enough, I used T.putStrLn
before but changed it to save a line by not importing Data.Text.IO
). I was deliberately trying to make them fit on a single screen, maybe that's good enough? I like the idea of having examples that are not super trivial but then constraining the line count poses a challenge.
For your second example, while it is a nice example of deriving strategies and a custom, interesting reduction operator, it's somewhat sad that we need 3 language extensions as well as GHC Generics
Again, I fully agree with you. When I wrote it, I somehow missed the uniformEnumM
function from random
which is exactly what I needed, so with that no extensions or generics are necessary (https://play.haskell.org/saved/4kpl6pkS).
If I come up with some other examples (something with parser combinators could be cool), I'll post them here for your consideration.
When I wrote it, I somehow missed the uniformEnumM function from random which is exactly what I needed, so with that no extensions or generics are necessary (https://play.haskell.org/saved/4kpl6pkS).
I like it! I assume you're okay with sharing these programs under the existing license of the playground packages (i.e. MIT)? :)
If I come up with some other examples (something with parser combinators could be cool), I'll post them here for your consideration.
Yes, please do.
Suggestions from other people are also welcome, though we try to not let the number of example programs grow without bound. :)
Great! I have no issue with the licensing.
Feature request
With the aim of creating a good first impression of the language for a hypothetical newcomer visiting the playground from the haskell.org homepage, I'd like to suggest choosing some examples that are easily grokked and showcase practical features. I do like the
quicksort
example because it is simple and to the point, however, I find the twomergesort
examples less compelling because the implementations, though interesting, are not easily followed.I drafted a few ideas which I think demonstrate useful Haskell principles and that are relatively beginner friendly. This one shows some basic domain modeling using ADTs:
And this one shows some event processing and instance derivation techniques: