What is the type of Nothing in Haskell?

后端 未结 5 996
北恋
北恋 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:41

    Is this not in contradiction with the rule the only concrete types can have values?

    Since functions are first-class values in Haskell, this purported rule would mean that polymorphic functions such as map and foldr would be impossible to implement.

    There are, in fact, a lot of polymorphic non-function values in Haskell, such as

    1 :: Num a => a
    Nothing :: Maybe a
    [] :: [a]
    Left 1 :: Num a => Either a b
    

    etc. These values exist for every instantiation of a (and b).

提交回复
热议问题