fslang-suggestions icon indicating copy to clipboard operation
fslang-suggestions copied to clipboard

Add `___` / `nyi` to the `FSharp.Core`

Open Krzysztof-Cieslak opened this issue 2 years ago • 8 comments

I propose we add a new helper function to the FSharp.Core that would be a shortcut for declaring unimplemented values/functions.

The existing way of approaching this problem in F# is to create this function manually.

let ___<'a> = failwith "not yet implemented"

However, manual implementation means there's no well-known symbol whose presence can be discovered by static code analysis.

Pros and Cons

The advantages of making this adjustment to F# are that it would enable tooling to implement "typed holes"-like functionality

The disadvantages of making this adjustment to F# are increasing API surface exposed by FSharp.Core.

Extra information

Estimated cost (XS, S, M, L, XL, XXL): XS (?)

Related suggestions: https://github.com/fsharp/fslang-suggestions/issues/779

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • [x] This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • [x] I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • [x] This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • [x] This is not a breaking change to the F# language design
  • [x] I or my company would be willing to help implement and/or test this

For Readers

If you would like to see this issue implemented, please click the :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.

Krzysztof-Cieslak avatar May 31 '23 11:05 Krzysztof-Cieslak

@Krzysztof-Cieslak Should this include CompilerMessage too?

open System
open System.Runtime.CompilerServices
[<CompilerMessage("Not yet implemented", 10003, IsError = false)>]
[<NoDynamicInvocation; MethodImpl(MethodImplOptions.AggressiveInlining)>]
let inline ___<'a> : 'a = raise(NotImplementedException("Not yet implemented"))

let foo (a: int) = ___

Will also result in

warning FS10003: Not yet implemented

In compile-time

vzarytovskii avatar May 31 '23 11:05 vzarytovskii

Yeah, +1 for including CompilerMessage.

Krzysztof-Cieslak avatar May 31 '23 15:05 Krzysztof-Cieslak

This is a good idea, editor could then put all such occurences into a task list.

I have used the "rocket" icon to indicate preference for "nyi" until a better voting scheme exists to pick between the two proposed options. (My reasoning: I roughly remember I have used multiple underscores in regular code before for something else; and "nyi" feels more explicit and yet easier to type)

T-Gro avatar May 31 '23 18:05 T-Gro

nyi is hard to understand and remember. It would probably the least intuitive non-operator expression to read in fsharp.

notImplemented notimplemented or notYetImplemented would be better.

charlesroddie avatar Jun 04 '23 11:06 charlesroddie

Simple "todo" might be a good name too and it matches with what ide usually look for in comments

En3Tho avatar Jun 04 '23 20:06 En3Tho

Smalltalks do this by defining exceptions, for example NotYetImplemented and ShouldBeImplemented.

The advantage to exceptions is that not only can tooling find and present these, but it is also possible to handle them as desired at runtime. I've treated NotYetImplemented as an exception that can be caught and suppressed. It represents desired future not yet implemented function. ShouldBeImplemented is something required and results in a runtime exception.

And of course there can be helper functions that call these.

Here is a bit of a discussion http://forum.world.st/not-yet-should-be-implemented-td4852379.html

jbeeko avatar Jun 05 '23 01:06 jbeeko

just copy & paste:

let foo (a: int) = failwith "not yet implemented"

foo 0;;

Not bad either!

xp44mm avatar Jul 11 '23 12:07 xp44mm

nyi is hard to understand and remember. It would probably the least intuitive non-operator expression to read in fsharp.

notImplemented notimplemented or notYetImplemented would be better.

Or even just notImpl, which keeps with the spirit of invalidArg.

jwosty avatar Jul 11 '23 16:07 jwosty