how does 'undefined' work in Haskell

后端 未结 6 1401
广开言路
广开言路 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:49

    If I try undefined in GHCi, I get an exception:

    Prelude> undefined
    *** Exception: Prelude.undefined
    

    Therefore, I suppose that it's just implemented as throwing an exception:
    http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html#g:2

提交回复
热议问题