List Operation -- Haskell

Source: Internet
Author: User

1. In Haskell, the string is indeed the syntactic sugar of the character array.

2. merge list

In Haskell, the combined list is implemented using the ++ OPERATOR:

Here, we can also see the relationship between strings and character arrays.

However, the ++ operator traverses the list on the left. The longer the list, the slower the access. In this case, it is better to use:

However, the: operator can only connect one element and one list:

So from above, why can't it be [[, 3], 6], but an error is reported? This is because the Haskell list can only accommodate the same type of elements:

Also, since we have all said that the string is actually a character array, you can put these operations in the string as well:

3. List Index

In conventional languages, we usually get used to brackets and subscripts to take an element in the list. But this syntax of Haskell is very strange!

4. List compare size

In fact, it is easy to imagine that the comparison is always from the first element:

However, the comparison can only be based on the same type; otherwise, an error is returned!

5. Common functions

When the list is a stack and a queue, such a function is generated:

Some frequently used:

6. Range

Interval is a very useful thing. Now every time I see the for loop assigning values to arrays, It is a headache.

This is a smart guy.

But he is not smart enough. I want to output 2, 4, 8, 16, and he will be powerless.

7. Evaluate inertia

In the previousArticleThe value of inertia.

Both cycle and repeat generate an infinitely long list, .................

Haskell does not persistently calculate all and then calculate, but calculates the value based on the calculation. This is called the inert value.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.