Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Usage of type (Pietro Grandinetti) 2. Re: Usage of type (Francesco Ariis) ---------------------------------------------------------------------- Message: 1 Date: Tue, 8 Dec 2020 16:23:35 +0000 From: Pietro Grandinetti <pietro....@hotmail.it> To: "beginners@haskell.org" <beginners@haskell.org> Subject: [Haskell-beginners] Usage of type Message-ID: <pr2pr09mb30034ba17ecddf462d19f82efc...@pr2pr09mb3003.eurprd09.prod.outlook.com> Content-Type: text/plain; charset="iso-8859-1" Hi, 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. 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 Title = String type Author = String type Sentence = String type Paragraph = [Sentence] type Abstract = Paragraph type Content = [Paragraph] type Date = Day data Essay = Essay { title :: Title , authors :: [Author] , pubDate :: Date , startDate :: Date , abstract :: Abstract , content :: Content } deriving (Show) makeTitle :: String -> Title makeTitle x = x::Title makePar :: String -> Paragraph makePar = splitOn sep where sep = "." makeContent :: String -> Content makeContent x = map makePar $ splitOn sep x where sep = "\n\n" unboxPar :: Paragraph -> String unboxPar = intercalate ". " unboxContent :: Content -> String unboxContent x = intercalate "\n\n" $ map unboxPar x Thanks, Pete -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20201208/b0b49695/attachment-0001.html> ------------------------------ Message: 2 Date: Tue, 8 Dec 2020 19:42:30 +0100 From: Francesco Ariis <fa...@ariis.it> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Usage of type Message-ID: <20201208184230.GE2781@extensa> Content-Type: text/plain; charset=utf-8 Hello Pietro, Il 08 dicembre 2020 alle 16:23 Pietro Grandinetti ha scritto: > Hi, > > 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, etc.). > 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`). —F ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 149, Issue 3 *****************************************