Haskell Types and Typeclasses

Source: Internet
Author: User

You can use the : T command to detect an expression type.

  A definite type must be capitalized in the first letter.

First, Types

  Char

  Bool

  Int(bounded, high efficiency compared to integer type)

  Integer(unbounded, less efficient compared to type int)

  Float

  Double

  The type of a Tuple depends on the length and the type of the element.

  The type of List depends only on the type of the element.

Second, typeclasses

  "= =" represents the constraint.

  Eq: Can compare equality.

  Ord: can compare size.

  Compare: Take two ord with the same type of value as the parameter, the result is lt,gt,eq three cases (less than/greater than/equal).

  Show: Available string representation.

Show: Converts the member type in show to a string.

  Read: Inverse with show.

Read: Converts a string to a member type in read. However, to identify the type of output, an ambiguous conversion cannot be performed. Read "1" is the wrong expression, and read "1":: int is the correct expression.

  Enum: Represents a type that can be contiguous.

succ: Forward.

pred: successor.

  bounded: have boundaries.

minbound: Lower boundary. Example, Minbound:: int expression is to see what the lower bound of the int type is.

maxbound: Upper border. Example, Maxbound:: An int expression is a view of what the upper bound of an int type is.

  Num: number.

  Integral: Integer. include int and integer types

  floating: Floating-point numbers, including float and double types.

fromintegral: Converts the integral to num type.

Third, the understanding of types and typeclasses.

  1. An expression can belong to only one type, but may belong to a variety of typeclasses.

2. To understand type, an expression can only belong to one type. To understand Typeclass as attributes, an expression can have multiple properties.

  3. Expressions that belong to the same type will inevitably have the same properties. But expressions that have the same properties do not necessarily belong to the same type.

Haskell Types and Typeclasses

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.