Opened 9 years ago

Last modified 3 months ago

#393 new feature request (None)

functions without implementations

Reported by: c_maeder Owned by: simonpj
Priority: normal Milestone:
Component: Compiler (Type checker) Version: None
Keywords: Cc: tomasz.zielonka@…, maeder@…, pho@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Moderate (less than a day)
Test Case: Blocked By:
Blocking: Related Tickets:

Description (last modified by igloo)

Allow to declare a function by only supplying its type
signature.
This feature shall enhance rapid prototyping by fixing
an interface but leaving some functions unimplemented.

Currently this can be (only) simulated by supplying
dummy implementations, like 

f :: ...
f = undefined

Since it is possible to supply dummy data types by
"data T" (not followed by "="), allowing functions
without implementations seems almost to be a logical
consequence. Surely, the compiler should emit warnings
for missing implementations.

It would be nice if such function declarations via type
signatures could be repeated at any position within a
module. 

Change History (19)

comment:1 Changed 7 years ago by igloo

  • Architecture set to Unknown
  • Description modified (diff)
  • Difficulty set to Unknown
  • Milestone set to 6.8
  • Operating System set to Unknown

comment:2 Changed 7 years ago by maeder@…

  • Architecture changed from Unknown to Multiple
  • Component changed from None to Compiler (Type checker)
  • Difficulty changed from Unknown to Easy (1 hr)
  • Operating System changed from Unknown to Multiple
  • Owner changed from nobody to simonpj
  • Priority changed from lowest to normal
  • severity changed from minor to normal
  • Status changed from assigned to new

comment:3 Changed 7 years ago by guest

from my POV, it's even faster to write "f=undefined" rather than signature, but i don't use sugnatures anyway :)

btw, if this feature will be implemented, it will be better to generate

f = error "Call to undefined f declared at Foo.hs:63"

comment:4 Changed 7 years ago by guest

  • Cc tomasz.zielonka@… added

comment:5 Changed 7 years ago by maeder@…

  • Cc maeder@… added

comment:6 Changed 7 years ago by guest

  • Cc changed from tomasz.zielonka@gmail.com;maeder@tzi.de to tomasz.zielonka@gmail.com,maeder@tzi.de

comment:7 Changed 6 years ago by simonmar

  • Milestone changed from 6.8 branch to _|_

No immediate plans to implement this.

comment:8 Changed 6 years ago by PHO

  • Cc pho@… added

comment:9 Changed 6 years ago by simonmar

  • Architecture changed from Multiple to Unknown/Multiple

comment:10 Changed 6 years ago by simonmar

  • Operating System changed from Multiple to Unknown/Multiple

comment:11 Changed 5 years ago by maeder

comment:12 Changed 4 years ago by simonmar

  • Difficulty changed from Easy (1 hr) to Easy (less than 1 hour)

comment:13 Changed 4 years ago by simonmar

  • Difficulty changed from Easy (less than 1 hour) to Moderate (less than a day)
  • Type of failure set to None/Unknown

comment:14 Changed 3 months ago by jgallag8

I am new to GHC, and I am interested in tackling this as my first task. Is there still interest in adding this feature? If so, I'll dive right in. Any pointers are appreciated.

comment:15 Changed 3 months ago by goldfire

I'd like this, for one. As someone said previously, GHC should surely emit a warning when compiling an undefined function. And, I like the suggestion above of an informative error call instead of just using undefined. Thanks for rolling up your sleeves!

comment:16 Changed 3 months ago by simonpj

I suggest

  • A language extension flag -XUndefinedFunctions or something
  • In the renamer you'll have to arrange to create a binder for a signature that lacks a corresponding binding; and give an warning (rather than an error) for such signatures.
  • I suggest that you actually add the definition f = error "Missing definition for f" (or whatever) in the desugarer. GHC generally tries NOT to mess with the source code until desugaring, so that you can always show exactly what the user wrote.

Happy to discuss when you get a bit further

Simon

comment:17 Changed 3 months ago by simonmar

For what it's worth, this is part of #5791

comment:18 Changed 3 months ago by jgallag8

Simonpj - Thanks very much for the advice. If I need more pointers, I'll let you know once I have become a little more familiar with the code base.

Simonmar - Do you suggest the two be handled together?

comment:19 Changed 3 months ago by simonmar

I think that this is another kind of "deferred error", in the same sense of -fdefer-type-errors, and there are lots of other kinds of errors that we want to defer (e.g. out-of-scope identifiers). So all I'm suggesting is that we should bear this in mind, and perhaps use a consistent naming convention for flags, e.g. this particular one could be -fdefer-missing-decl-errors, which would eventually become part of -fdefer-renamer-errors.

Note: See TracTickets for help on using tickets.