Haskell Note (iii) type system

Source: Internet
Author: User

types (type)

Haskell type system static type system, at compile time know the data type, so different types of value operations at compile time will be error, such as with Boolean and integer operation, in C language this operation will not error. Haskell supports type derivation using the: T command followed by any available expression, you can get the type of the expression, such as: T ' a ' will output ' a ':: Char indicates a is a char type.

A function also has a type, it is a good practice to give it a definite type declaration when writing a function, and there is no special difference between the parameters and the callback value. The return value is the last item, and the parameter is the first three items, such as

  Addthree:: int, int, int., int   
  addthree x y z = x + y + Z
Int,integer all represent shaping, integer unbounded, can represent infinite number of float single precision, double doubles, BOOL Boolean, Char character, [char],string string a,b,c,d ... And so the type represented by the letter is a variable type, for example: T head looks at the type of head function, and the head is shown: [A]->a means that the head function input is a list of any variable, and the output is any variable. A good habit when writing a function is to declare the type of the function first. type interface? type constraint? (typeclasses)

When you see this name, the direct idea is the type class, but this is not related to the class in OOP, you can regard him as an interface, that is, the type that belongs to a certain typeclasses, must realize the function of the typeclasses, it sounds very round, Because there is no contact with functional programming, so some concepts and command-style programming is not, it's okay, to the back of the understanding, I do not understand. Oh.

EQ Equality Judgment Interface

Ord contains types that can compare big

The type of show that can be represented by a string

Read is the opposite of show

Enum members are continuous types

Bounded members have upper and lower limits


This tutorial refers to the Haskell Fun Guide, which is a learning note for this guide, but has joined some of my own ideas and summaries, first of all, thanks to the author of the Haskell Guide bonus and the mainland translator Fleurer and Taiwanese translator MnO2, thank you for your previous work.

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.