[Haskell-beginners] How best to do this?

Brent Yorgey byorgey at seas.upenn.edu
Wed May 1 13:33:09 CEST 2013


Ah, yes, a warning for literals like [5..2] sounds like an excellent
idea.  Why don't you file a feature request at

  http://hackage.haskell.org/trac/ghc/

?

-Brent

On Wed, May 01, 2013 at 12:35:36PM +0200, Michael Peternell wrote:
> @Brent:
> By reading your mails I got an idea...
> 
> how about generating a compiler warning when someone types a literal like [5..2].
> 
> "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."
> 
> That would be a really beginner-friendly warning.
> 
> But I also think that we shouldn't catch this kind of mistake at runtime, because it may be the expected behavior in many cases.
> 
> Michael
> 
> Am 29.04.2013 um 23:54 schrieb Brent Yorgey:
> 
> > Oh, yes, I suppose it could.
> > 
> > In any case, I am still in favor of the existing semantics -- it is
> > simple and consistent (and sometimes even useful).  "Do what I
> > mean"-style semantics with special cases end up generating more pain
> > than they solve.
> > 
> > -Brent
> > 
> > On Mon, Apr 29, 2013 at 02:29:43PM -0400, David McBride wrote:
> >> Couldn't it just use fromEnum and compare the integers you get and
> >> figure out which is bigger?
> >> 
> >> On Mon, Apr 29, 2013 at 2:17 PM, Brent Yorgey <byorgey at seas.upenn.edu> wrote:
> >>> But then \x y -> [x .. y]  would have to have the type
> >>> 
> >>>  (Ord a, Enum a) => [a]
> >>> 
> >>> whereas now it just has the Enum constraint.  Either that or else the
> >>> notation would work differently for literals vs. expressions but that
> >>> would be just awful.
> >>> 
> >>> -Brent
> 
> 
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners



More information about the Beginners mailing list