What is the role of 'bottom' (⊥) in Haskell function definitions?

后端 未结 4 1297
醉酒成梦
醉酒成梦 2021-02-05 07:35

I don\'t understand the role played by bottom ( or _|_) in Haskell function definitions.

The definition of zip for example describes it as \"r

4条回答
  •  故里飘歌
    2021-02-05 07:58

    Riffing on AJFarmar's answer, I think this critical point was not made explicit:

    • _|_ is not a valid literal or identifier in Haskell code!
    • And therefore, zip [] _|_ = [] isn't valid code either!

    That is implicit in what AJFarmar means by this quote:

    [T]he line zip [] _|_ = [] does not act as a pattern match but an equation, stating the equality of zip [] _|_ and [].

    To make it very crystal clear, zip [] _|_ = [] appears in the documentation comment for the definition of zip. It's not Haskell code—it's an English-language comment written in an informal technical notation that looks a little bit like Haskell code. Or, in other words, pseudo-code.

提交回复
热议问题