
#7881: Warning for pointless ranges like [5..2] -----------------------------+---------------------------------------------- Reporter: mpe | Owner: Type: feature request | Status: new Priority: normal | Component: Compiler Version: 7.6.3 | Keywords: beginner,warning Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Blockedby: Blocking: | Related: -----------------------------+---------------------------------------------- Haskell beginners sometimes tend to write ranges like [3..1] or [5..2] and assume that the result will be [3,2,1] or [5,4,3,2]. This is not the case of course. I suggest that literals like [5..2] generate a warning at compile time, analogous to: "Foo.hs:32: Warning: Literal list [5..2] evaluates to [] because 5 > 2 and the default step size is +1. Replace the literal with the empty list or with [5,4..2] to suppress this warning." In my opinion this should only be a compile time warning, not a runtime warning. If a > 3 and b is < 3 and you write [a..b] the result is still [], but that mistake can only be caught at runtime, and requires an additional run-time check. In some cases it may even be the desired behaviour to let [a..b] evaluate to [] if a>b. On the other hand, a literal expression like [5..2] is most likely an error, because if the user would expect [5..2] to evaluate to [], he would simply write []. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7881 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler