What is () in Haskell, exactly?

前端 未结 6 1627
星月不相逢
星月不相逢 2020-12-12 15:55

I\'m reading Learn You a Haskell, and in the monad chapters, it seems to me that () is being treated as a sort of \"null\" for every type. When I check

6条回答
  •  执笔经年
    2020-12-12 16:05

    It is called the Unit type, usually used to represent side effects. You can think of it vaguely as Void in Java. Read more here and here etc. What can be confusing is that () syntactically represents both the type and its only value literal. Also note that it is not similar to null in Java which means an undefined reference - () is just effectively a 0-sized tuple.

提交回复
热议问题