[Haskell-beginners] Nested folds

Francesco Ariis fa-ml at ariis.it
Sun Dec 13 22:47:42 UTC 2020

Il 13 dicembre 2020 alle 19:04 Pietro Grandinetti ha scritto:
> Yes, that helped. However, I believe I shouldn't remove the `makeSentence`.
> A user of the module is not supposed to know what a `Sentence` is, hence I
> must provide a function such as `makeSentence`.

But they will know, a type synonym is just a way to make signatures
prettier/more informative, a program like this

    foo :: String
    foo = "foo"

    k = sentCharCount foo

will _not_ be refused by the compiler. IF and when — in the future — you
decide to use newtype/data then you will get a compiler error (and in turn
would need a constructor with signature `:: String -> Sentence`.

> Do you have any feedback on my questions 1,2 and 3?

The functions are clearly written, there is some duplication because of
the type synonyms (i.e. `parWordCount` and `contWordCount` are the same
Do not worry about it now and revisit the exercise once you start
using `newtype` and `data` + typeclasses

More information about the Beginners mailing list