how does 'undefined' work in Haskell

后端 未结 6 1424
广开言路
广开言路 2021-02-05 04:23

I\'m curious about the \'undefined\' value in Haskell. Its interesting because you can put it just about anywhere, and Haskell will be happy. The following are all a-ok

6条回答
  •  时光取名叫无心
    2021-02-05 04:48

    There are two separated things to note about undefined:

    • You can put undefined almost everywhere and typechecker will be happy. It's because undefined have type (forall a. a).
    • You can put undefined almost everywhere and it will have some well defined representation at run time.

    For the second, GHC commentary clearly says:

    The representation of ⊥ must be a pointer: it is an object that when evaluated throws an exception or enters an infinite loop.

    For more details you might want to read the paper Spinless Tagless G-Machine.

提交回复
热议问题