<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi,</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Playing around with code (very few lines) that represents long-form articles. I'd like to understand:</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
1- if the usage of `type' is correct, or if I should prefer `newtype', or something different altogheter.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
2- what's the more idiomatic way to do the boxing and unboxing of renamed types? See last 2 functions in the code.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
import Data.Time (Day)
<div>import Data.List (intercalate)</div>
<div>import Data.List.Split (splitOn)</div>
<div><br>
</div>
<div>type Title            = String</div>
<div>type Author       = String</div>
<div>type Sentence   = String</div>
<div>type Paragraph  = [Sentence]</div>
<div>type Abstract     = Paragraph</div>
<div>type Content     = [Paragraph] </div>
<div>type Date           = Day</div>
<div><br>
</div>
<div>data Essay     = Essay {</div>
<div>    title       :: Title</div>
<div>    , authors   :: [Author]</div>
<div>    , pubDate   :: Date</div>
<div>    , startDate :: Date</div>
<div>    , abstract  :: Abstract</div>
<div>    , content   :: Content</div>
<div>    } deriving (Show)</div>
<div><br>
</div>
<div>makeTitle :: String -> Title</div>
<div>makeTitle x = x::Title</div>
<div><br>
</div>
<div>makePar :: String -> Paragraph</div>
<div>makePar =  splitOn sep</div>
<div>    where sep = "."</div>
<div><br>
</div>
<div>makeContent :: String -> Content</div>
<div>makeContent x = map makePar $ splitOn sep x</div>
<div>    where sep = "\n\n"</div>
<div><br>
</div>
<div>unboxPar :: Paragraph -> String</div>
<div>unboxPar = intercalate ". "</div>
<div><br>
</div>
<div>unboxContent :: Content -> String</div>
<div>unboxContent x = intercalate "\n\n" $ map unboxPar x</div>
<br>
Thanks,</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Pete</div>
</body>
</html>