[Haskell-beginners] Usage of type
fa-ml at ariis.it
Tue Dec 8 18:42:30 UTC 2020
Il 08 dicembre 2020 alle 16:23 Pietro Grandinetti ha scritto:
> Playing around with code (very few lines) that represents long-form articles. I'd like to understand:
> 1- if the usage of `type' is correct, or if I should prefer `newtype', or something different altogheter.
Your usage of `type` is correct. The idea is that you start with type
and can easily switch to newtype if the need arises (typeclass reasons,
> 2- what's the more idiomatic way to do the boxing and unboxing of renamed types? See last 2 functions in the code.
> import Data.Time (Day)
> import Data.List (intercalate)
> import Data.List.Split (splitOn)
> type Sentence = String
> type Paragraph = [Sentence]
> type Content = [Paragraph]
> unboxPar :: Paragraph -> String
> unboxPar = intercalate ". "
> unboxContent :: Content -> String
> unboxContent x = intercalate "\n\n" $ map unboxPar x
unboxPar and unboxContent are fine, I would personally name them slightly
differently (`renderPar` and `renderContent`).
More information about the Beginners