Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#1256 closed feature request (fixed)

GHC warns about omitting type signatures; would be more helpful if it supplied inferred type signature

Reported by: guest Owned by:
Priority: low Milestone: 6.8.1
Component: Compiler Version: 6.6
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

When I'm just messing around with very complex (or even fairly simple) Haskell programs, like Darcs or GHC, it often is much easier to just comment out the type signatures and then proceed to code. But the problem is that sometimes I then can't figure out what the new type signature for a function is!

Normally I would just fire up GHCi and do a :type request, but that's not always possible, particularly with really complex ones (I still haven't figured out how to successfully load Darcs into GHCi). But everytime it compiles, -Wall causes GHC to spit out a warning that the type signature is not provided - but it doesn't say what it infers the type signature to be! That information would be very useful to me (I could copy-and-paste it, or specialize it a bit more, or realize that while my program compiles and type-checks, it isn't actually doing what I thought, etc.)

So when GHC warns that a type signature wasn't found, could it maybe also print out what type signature *was* inferred? It'd make the warning much more useful, and doesn't seem like a big change.

Change History (8)

comment:1 Changed 7 years ago by igloo

  • Milestone set to 6.8

It's not entirely trivial as I don't think we have infered a type at the point where we give the message, and if we have an error like a use of an unbound variable then we never will have the type.

We might be able to do something if we don't get an error before typechecking is finished, though, or perhaps a flag like -ddump-minimal-imports but for types.

comment:2 Changed 7 years ago by simonpj

We already do have such a flag: -ddump-types.

Still the suggestion re warnings is a good one; I'll think on it.

Simon

comment:3 Changed 7 years ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed

I've committed a patch that implements this idea:

Foo1.hs:4:0:
    Warning: Definition but no type signature for `f'
	     Inferred type: f :: forall t. [t] -> t

Thanks for the suggestion.

Simon

comment:4 Changed 7 years ago by Isaac Dupree

Perhaps the type should be shown without the unnecessary forall's (which aren't commonly written in type-signatures when not needed, and aren't Haskell98)?

(BTW, having that in the warning at all is great :)

comment:5 Changed 7 years ago by simonpj

See #1308 for why omitting the forall is far from a no-brainer.

Simon

comment:6 Changed 6 years ago by igloo

  • Milestone changed from 6.8 branch to 6.8.1

comment:7 Changed 6 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:8 Changed 6 years ago by simonmar

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