haskell / alex

A lexical analyser generator for Haskell
https://hackage.haskell.org/package/alex
BSD 3-Clause "New" or "Revised" License
298 stars 82 forks source link

Fix warnings about non-exhaustive patterns #135

Closed josephcsible closed 5 years ago

josephcsible commented 5 years ago

The utf8encode function always returned a list of at least one element, but the type system didn't prove this, leading to spurious warnings when taking the first element of the returned list. Fix this by returning a tuple with the first element separate instead. (I would have used Data.List.NonEmpty but it looks like we still support ancient GHC versions that didn't yet have it.)

josephcsible commented 5 years ago

I left a compatibility shim to provide the old interface under the old name, in case any users' Haskell code calls that for some reason. If users aren't supposed to do that anyway, let me know and I can take it out.

josephcsible commented 5 years ago

It looks like BangPatterns isn't enabled now, but I don't see any reason that it couldn't be enabled. For strictness, would you rather I do that, or that I use the case-with-one-pattern trick everywhere?

simonmar commented 5 years ago

No, let's do it without BangPatterns, the user might be surprised if Alex turns it on.

josephcsible commented 5 years ago

Okay, done.