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. understanding type constructors and value constructors (Anwar Ludin) 2. Re: understanding type constructors and value constructors (Alex Belanger) 3. Re: understanding type constructors and value constructors (Imants Cekusins) 4. Re: understanding type constructors and value constructors (Anwar Ludin) ---------------------------------------------------------------------- Message: 1 Date: Thu, 14 Sep 2017 06:04:26 +0200 From: Anwar Ludin <anwar.lu...@gmail.com> To: Beginners@haskell.org Subject: [Haskell-beginners] understanding type constructors and value constructors Message-ID: <camjsputedmbruzqhygfvf6dkekvb_uwqrz4nhpr3t0znr9v...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hello everyone, I have just started studying Haskell and I am having a hard time understanding type and value constructors. So to create a new type, you write something like: data FinancialInstrument = Financial String Double deriving (Eq, Show) and then you can write: ibm = Financial "ibm" 150 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: data FinancialInstrument = FinancialInstrument String Double deriving (Eq, Show) 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? Once a value has been constructed, how can I access its fields? Is there a way to create values using named parameters? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170914/ebcf899a/attachment-0001.html> ------------------------------ Message: 2 Date: Thu, 14 Sep 2017 00:56:59 -0400 From: Alex Belanger <i.caught....@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] understanding type constructors and value constructors Message-ID: <cadsky2y_tzmaw03_ur8fyqmej04ogfzjnq10ejqzmkyegaz...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" I'm on my phone which makes replying painful, but consider: data Weekday = Monday | Tuesday | Wednesday | Thursday | Friday data Shape = Circle Int | Rectangle Int Int Int Int | Triangle Int Int data Either a b = Left a | Right b Cheers, Alex On Sep 14, 2017 12:05 AM, "Anwar Ludin" <anwar.lu...@gmail.com> wrote: > Hello everyone, > > I have just started studying Haskell and I am having a hard time > understanding type and value constructors. > > So to create a new type, you write something like: > > data FinancialInstrument = Financial String Double > deriving (Eq, Show) > > and then you can write: > > ibm = Financial "ibm" 150 > > 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: > > data FinancialInstrument = FinancialInstrument String Double > deriving (Eq, Show) > > 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? > > Once a value has been constructed, how can I access its fields? > > Is there a way to create values using named parameters? > > Thanks! > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170914/ec5fea45/attachment-0001.html> ------------------------------ Message: 3 Date: Thu, 14 Sep 2017 08:18:07 +0300 From: Imants Cekusins <ima...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] understanding type constructors and value constructors Message-ID: <cap1qinztxftwnv3qbsfqwdoww-oru7sr8x0h3rc89_9ww3v...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" This chapter details it: http://book.realworldhaskell.org/read/defining-types-streamlining-functions.html More questions are welcome, of course. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170914/84a62064/attachment-0001.html> ------------------------------ Message: 4 Date: Thu, 14 Sep 2017 07:19:24 +0000 From: Anwar Ludin <anwar.lu...@gmail.com> To: "The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell" <beginners@haskell.org> Cc: "The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell" <beginners@haskell.org> Subject: Re: [Haskell-beginners] understanding type constructors and value constructors Message-ID: <local-18a706e0-a...@nylas-mail.nylas.com> Content-Type: text/plain; charset="utf-8" An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170914/69d9acc0/attachment-0001.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 111, Issue 10 ******************************************