Haskell 入门 - 零碎版

发布时间 2023-09-30 13:25:28作者: UPeRVv

Haskell 2010

4. Declarations and Bindings

4.1 Overview of Types and Classes

4.1.2 Syntax of Types

  • Type variables
  • Type constructors
    • type constants with kind ∗
    • types with kind ∗ → ∗
    • built-in type constructors
      • trivial type, as () with *
      • function type, as (->), kind ∗ → ∗ → ∗
      • list type, as [], kind ∗ → ∗
      • tuple types, as (,), (,,), and so on, kind ∗ → ∗ → ∗ and so on.
    • Special syntax, built-in type constructors for functions, tuples, and lists,
      • function type, t1 -> t2
      • tuple type, (t1, . . . , tk) 
      • list type, [t]
  • Type application, 接收类型化参数,具化为新类型
  • A parenthesized type, form (t), is identical to the type t.

4.2 User-Defined Datatypes

  • algebraic datatypes (data declarations)
  • renamed datatypes (newtype declarations)
  • type synonyms (type declarations)

4.2.1 Algebraic Datatype Declarations

示例:



-- libraries/ghc-prim/GHC/Types.hs
data List a = [] | a : List a