What is the type of Nothing in Haskell?

后端 未结 5 993
北恋
北恋 2021-01-01 10:51

I\'m at page 118 of the book \"Learn You a Haskell for Great Good!\"

It is written there:

ghci> :t Nothing 
Nothing :: Maybe a

H

5条回答
  •  不知归路
    2021-01-01 11:51

    In some sense, you're right. There are no values of type forall a.Maybe a. Every Maybe value you construct will actually have some definite type Maybe tau, where tau may be known or not, but is some definite type.

    The notation Nothing :: forall a.Maybe a just tells us that whenever we use the expression Nothing, it will construct a value of the expected Maybe type.

提交回复
热议问题