Opened 10 years ago

Closed 22 months ago

#1404 closed feature request (wontfix)

allow more type signatures

Reported by: Isaac Dupree Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 6.6.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

(idea triggered by #393)

Allow multiple copies of a type-signature in a module, such that it is an error if they're not equivalent, but they don't have to be syntactically equal ( f :: ShowS f :: String -> String is okay).

It would also be nice to allow any name in scope at top-level (even if imported) to be given a type signature. But that raises a question: can these type signatures give a more specific type than that of the raw imported function, the way normal function type signatures can with regards to their implementation?

Use cases: (1. making sure multiple implementations give the same interface, generally varying by #ifdef) (2. asserting that something's type can be specified in two different weird ways). I don't really want to abandon having a type-signature right above every function definition even if it is a duplicate.

(1.) would be fixed by allowing type signatures in export lists instead. I suppose these could be more restrictive than in the module and not affect the module, e.g.

module X (idN :: Int -> Int, true) where
idN n = n
true :: Bool
true = idN True

Change History (5)

comment:1 Changed 10 years ago by igloo

Component: CompilerCompiler (Type checker)
Milestone: _|_

You can do (1) with

foo :: type
#if ...
foo = ...
#else
foo = ...
#endif

(2) doesn't seem that useful to me personally.

Type sigs in export lists might be nice, as some people seem to like giving them as comments which then get out of sync with the actual types.

It might be worth starting a discussion on the Haskell' list about all this.

comment:2 Changed 9 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:3 Changed 9 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:4 Changed 4 years ago by morabbin

Type of failure: None/Unknown

Did said discussion ever happen?

comment:5 Changed 22 months ago by bgamari

Resolution: wontfix
Status: newclosed

It seems like the Backpack work addresses much of this by explicitly defining the publicly available interface of a package. Otherwise, the CPP approach proposed in comment:1 seems pretty reasonable to be.

If someone wants to take up this task and see whether there is consensus around allowing multiple signatures then feel free to reopen this.

Note: See TracTickets for help on using tickets.