[GHC] #7881: Warning for pointless ranges like [5..2]
GHC
cvs-ghc at haskell.org
Fri May 3 09:52:30 CEST 2013
#7881: Warning for pointless ranges like [5..2]
---------------------------------+------------------------------------------
Reporter: mpe | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.6.3
Keywords: beginner,warning | Os: Unknown/Multiple
Architecture: Unknown/Multiple | Failure: None/Unknown
Difficulty: Unknown | Testcase:
Blockedby: | Blocking:
Related: |
---------------------------------+------------------------------------------
Changes (by simonpj):
* difficulty: => Unknown
Comment:
I think this is a good idea. The gotcha is this:
{{{
newtype RInt = RI Int deriving( Eq, Show )
instance Ord RInt where
compare (RI a) (RI b) = compare b a
instance Enum RInt where
enumFromTo (RI a) (RI b) = map (RI . negate) [negate a .. negate b]
instance Num RInt where
fromInteger n = RI (fromInteger n)
main = print ([3..1] :: [RInt])
}}}
Here `RInt` has an `eunuFromTo` implementation that doesn't produce an
empty list!
So you need to wait till after the type checker, and bleat only for empty
ranges on known types like `Int`, `Integer`, `Char` and so on.
Fortunately the desugarer, which runs afer the type checker, has the right
plumbing to produce warnings.
If someone wants to do this, I'm open to a patch.
Simon
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7881#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list