Ticket #1902 (closed proposal: wontfix)

Opened 4 years ago

Last modified 3 years ago

Restrict the type of (^), (^^), and add genericPower, genericPower'

Reported by: igloo Owned by:
Priority: normal Milestone: Not GHC
Component: libraries/base Version: 6.8.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

This got a warm reception when I mentioned it in  http://www.haskell.org/pipermail/haskell-cafe/2007-June/027557.html so I'm formally proposing it now.

Note that this is a divergence from Haskell 98 (but the libraries already have a handful of small divergences, and Haskell' is just around the corner...).

In my opinion, (^) has the wrong type. Just as we have, for example,

(!!)         ::                 [a] -> Int -> a
genericIndex :: (Integral b) => [a] -> b   -> a

we should also have

(^)          :: (Num a)             => a -> Int -> a
genericPower :: (Num a, Integral b) => a -> b   -> a

(or some other function name). The same goes for (^^) (genericPower').

In my experience this would remove 99.9% of all defaulting (mostly where you write things like x^12 and 8^12), which means it's easier to get -Wall clean without having to put :: Int annotations everywhere.

The impact to GHC's bootlibs and extralibs is minimal. In most cases we have things like 2^15, where Int is clearly fine, although it happens to be defaulted to Integer currently. In Data.Complex we have 2 cases of e^(2::Int) which can now be beautified. There are several cases where the type is inferred to be Int anyway.

There are 3 files where we really do have an Integer, and it does matter. They are all for parsing numbers of the form 18e43, in base/Text/Read/Lex.hs, parsec/Text/ParserCombinators/Parsec/Token.hs and haskell-src/Language/Haskell/Lexer.hs.

Initial deadline: 1 Dec 2007.

Attachments

1902.patch Download (72.6 KB) - added by igloo 4 years ago.

Change History

Changed 4 years ago by igloo

Changed 4 years ago by sorear

  • cc sorear, lemming@… added

Also adding Henning Thielemann because he seconded on the mailing list.

Changed 4 years ago by igloo

  • cc lemming@… removed

I think the mailing list thread is a better place to judge concensus for proposals. Using the CC list doesn't give us a way for people to be against the proposal.

I've removed Henning again as he may not want to get a copy of all mails to the bug report.

Changed 4 years ago by sorear

  • cc sorear removed

Oh right, I had LSP consensus confused with bug voting. Oops.

Changed 4 years ago by igloo

  • status changed from new to closed
  • resolution set to wontfix

No consensus for the change.

Changed 3 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 3 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.