Better exception for non-exhaustive patterns in case

前端 未结 2 485
陌清茗
陌清茗 2020-11-22 17:03

Is there a way to get GHCi to produce better exception messages when it finds at runtime that a call has produced value that does not match the function\'s pattern matching?

2条回答
  •  名媛妹妹
    2020-11-22 17:20

    Try turning on warnings in ghci. This enables the compile time warnings you can get with ghc by passing -W, for example. You can do this several ways:

    ghci -fwarn-incomplete-patterns
    

    Or Neil Mitchell describes how he sets this up in his .ghci. Here is the relevant excerpt:

    :set -fwarn-incomplete-patterns
    

    You can manually enter this at ghci as well, but it would be a pain to do so each time you start it. Entered this way, it only works for statements entered at the prompt, not for loading files with :l. Instead you can put this comment at the top of the file you want to warn about incomplete patterns:

    {-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
    

提交回复
热议问题