functional programming - Haskell Cons Operator (:) -


I'm actually new to Haskell (actually I saw "Real World Haskell" from O'Reilly) and thought, "Hmm, I think I'll learn functional programming tomorrow) and I'm thinking: I have an item in the beginning of a list I can use the construction operator to add:

  1: [2,3] [1, 2,3]  

I found in the book Tried to create an example data type and then play with it:

  - A file Billing data = credit card int string string | cash on delivery | Invoice intermediate diving (show) --in $ HOME $ order command-list = [invoice 2345] $ order-list [invoice 2345] $ order-list = cacheon delivery: Order-list $ order-list [cash on delivery, cash on delivery, cash on delivery, cash on delivery, cash on delivery, cash on delivery, cash on delivery, cash on delivery, cash on delivery, cash on delivery, cash on delivery, cash on call Worry, cash on delivery, cash on delivery, ...-  

etc ... it repeats forever, because it is the use of lazy evaluation Does it?

- Edit -

OK, so it's heading in my head that order_list = CashOnDelivery: CashOnDelivery does not add order_list to the original order_list and Then set the result in the order list, but instead is recursive and creates an infinite list, always introduces cash on delivery to start own. Of course, now I remember that Haskell is a functional language and I have a basic order list Can not change the price, so i List of the end (or beginning, which should also do a simple "wedge on)?" Make a function that takes a list and a billing event as a logic, and then returns a list?

- Edit 2 -

OK, based on all the answers I am receiving and reference and mutual variables (i.e. use I am) lack of being able to pass an object ... I think I have already asked this question before and I have to really strict before I understand the answers to my questions I can expect before Go ahead in the paradigm ... I think what I was looking at is the function or how to write some thing, taking a list and an item, and returning a list under it is the name hence the function once Can be given more names than ever, without changing the name every time (as it was actually a program that will add the actual command to the order list, and the user will not have to think about the new name for it. Make a list every time, but attach a list to the same list).

You do this:

  $ command- list = [ Invoice 2345] $ command command list = cacheon delivery: order_list  

The important thing to note here is that you do not not just a cash on delivery < / Code> Add items to your first order_list . You are defining a new variable order_list which is not already associated with it; it is a recursive definition; order_list on the right refers to you order_list Defines the left side, not defined in the previous row. Due to this repetition, you get an infinite list.

I suspect that you really want to do something like this:

  $ order command list = [invoice 2345] $ order list [invoice 2345] $ command command_list2 = Cash On Delivery: Order-List $ Order_list 2 [Cash On Delivery, Invoice 2345]  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -