Opened 10 years ago

Last modified 5 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: newcomer Cc: tomasz.zielonka@…, pho@…, admin@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

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 (25)

comment:1 Changed 8 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 8 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 8 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 8 years ago by guest

  • Cc tomasz.zielonka@… added

comment:5 Changed 8 years ago by maeder@…

  • Cc maeder@… added

comment:6 Changed 8 years ago by guest

  • Cc changed from [email protected];[email protected] to [email protected],[email protected]

comment:7 Changed 7 years ago by simonmar

  • Milestone changed from 6.8 branch to _|_

No immediate plans to implement this.

comment:8 Changed 7 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 6 years ago by maeder

comment:12 Changed 5 years ago by simonmar

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

comment:13 Changed 5 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 15 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 15 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 15 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 15 months ago by simonmar

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

comment:18 Changed 15 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 15 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.

comment:20 Changed 7 months ago by rodlogic

Adding the source file and line number is also quite useful. So shouldn't the definition proposed by @simonpj include them? Or is there a specific reason not to?

In fact, shouldn't the exception thrown by undefined include the file & lineno so that the added definition would then become simply f = undefined, as requested in the original ticket? I have already been at a loss by an error such as *** Exception: Prelude.undefined without any references to where.

comment:21 Changed 7 months ago by rodlogic

  • Cc admin@… added

comment:22 Changed 7 months ago by maeder

  • Cc maeder@… removed

Wow, I've created this ticket 9 years ago and I got used to live without this feature, although it should be simple to implement. (I hope my old username c_maeder was deleted.)

To answer your question. Yes, source file and line number should be included (indicated by "or whatever")

Adding source file and line number to the Exception for undefined is obviously not so easy.

comment:23 Changed 7 months ago by maeder

also see #9049

comment:24 Changed 7 months ago by simonpj

Actually using this

f :: Int -> Int
f = _           -- Note "_" not "undefined"

plus compiling with -fdefer-type-errors, will give a runtime error when (and only when) f is called, giving file and line number. See the manual on typed holes.

See #9497 for making this a bit better.

Simon

comment:25 Changed 5 months ago by nomeata

  • Keywords newcomer added
Note: See TracTickets for help on using tickets.