<div dir="auto">I'm on my phone which makes replying painful, but consider:<div dir="auto"><br></div><div dir="auto">data Weekday = Monday | Tuesday | Wednesday | Thursday | Friday</div><div dir="auto"><br></div><div dir="auto">data Shape = Circle Int | Rectangle Int Int Int Int | Triangle Int Int</div><div dir="auto"><br></div><div dir="auto">data Either a b = Left a | Right b</div><div dir="auto"><br></div><div dir="auto">Cheers,</div><div dir="auto">Alex</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sep 14, 2017 12:05 AM, "Anwar Ludin" <<a href="mailto:anwar.ludin@gmail.com">anwar.ludin@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello everyone,<div><br></div><div>I have just started studying Haskell and I am having a hard time understanding type and value constructors.</div><div><br></div><div>So to create a new type, you write something like:</div><div><br></div><div>data FinancialInstrument = Financial  String Double</div><div>                                           deriving (Eq, Show)</div><div><br></div><div>and then you can write:</div><div><br></div><div>ibm = Financial "ibm" 150</div><div><br></div><div>OK all good. This initializes a FinancialInstrument. What I don't quite grasp is what is the purpose of Financial (the data/value constructor)? And from what I have read, you could have also written:</div><div><br></div><div>data FinancialInstrument = FinancialInstrument String Double</div><div>                                           deriving (Eq, Show)</div><div><br></div><div>To me the second expression is a lot closer to the typical OOP way of doing things (where the type name and constructor(s) have the same name). Why would someone prefer the first notation?</div><div><br></div><div>Once a value has been constructed, how can I access its fields?</div><div><br></div><div>Is there a way to create values using named parameters?</div><div><br></div><div>Thanks! </div></div>
<br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">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-<wbr>bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div></div>