<div dir="ltr"><div>> why can <font face="monospace">Book</font> take everything naked but my <font face="monospace">Day</font> version not?</div><div><br></div><div>The <font face="monospace">Day<font face="arial,sans-serif"> data type is actually just a newtype wrapper around an Int, which encodes the number of days since some point in the past - the docs more details: <a href="https://hackage.haskell.org/package/time-1.12/docs/Data-Time-Calendar.html">https://hackage.haskell.org/package/time-1.12/docs/Data-Time-Calendar.html</a>. So to use the data constructor directly as in the <font face="monospace">Book<font face="arial,sans-serif"> example, you'd have to give it the number of days directly, something like <font face="monospace"><a id="gmail-v:ModifiedJulianDay" class="gmail-def">ModifiedJulianDay</a> 1234<font face="arial,sans-serif"><span style="font-family:monospace"></span>. The helper function gives a more convenient way to construct a <font face="monospace">Day<font face="arial,sans-serif">. I believe this general approach of having functions to help you construct a data type is called 'smart constructors'. They're more common when the data constructors are not exported from a module, so the helper functions are the only way to create a value of that type - useful if you have some constraints you need enforced on your type.</font></font></font></font></font></font><br></font></font></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 1, 2021 at 10:41 AM Galaxy Being <<a href="mailto:borgauf@gmail.com">borgauf@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I am using the built-in data type <font face="monospace">Day</font> (<font face="monospace">Data.Time)</font> in two ways<div><br></div><div><font face="monospace">data PDate = PDate Day</font></div><div><br></div><div>or</div><div><br></div><div><font face="monospace">type PDate Day</font></div><div><br></div><div>doesn't seem to matter. But then this doesn't work</div><div><br></div><div><font face="monospace">testrec1 = PDate 2021 7 1</font></div><div><br></div><div>I always must use the "helper function" <font face="monospace">fromGregorian</font><br></div><div><br></div><div><font face="monospace">testrec0 = PDate (fromGregorian 2021 7 1)<br></font></div><div><font face="monospace">...</font></div><div><font face="monospace">PDate 2021-07-01</font><br></div><div><br></div><div>Looking at Real World Haskell examples</div><div><br></div><div><font face="monospace">data BookInfo = Book Int String [String]  deriving (Show)<br></font></div><div><font face="monospace">...</font></div><div><font face="monospace">myInfo = Book 9780135072455 "Algebra of Programming" ["Richard Bird", "Oege de Moor"]</font><br></div><div><br></div><div>I know there's a great Haskell lesson to learn here, so why can <font face="monospace">Book</font> take everything naked but my <font face="monospace">Day</font> version not?</div><div><br></div><div><br></div><div><div><div dir="ltr"><div dir="ltr"><div>⨽<br></div>Lawrence Bottorff<div>Grand Marais, MN, USA</div><div><a href="mailto:borgauf@gmail.com" target="_blank">borgauf@gmail.com</a></div></div></div></div></div></div>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>