fsharp / fslang-suggestions

The place to make suggestions, discuss and vote on F# language and core library features
341 stars 20 forks source link

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

Open Krzysztof-Cieslak opened 1 year ago

Krzysztof-Cieslak commented 1 year ago

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:

Please tick all that apply:

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.

vzarytovskii commented 1 year ago

@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

Krzysztof-Cieslak commented 1 year ago

Yeah, +1 for including CompilerMessage.

T-Gro commented 1 year ago

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)

charlesroddie commented 1 year ago

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.

En3Tho commented 1 year ago

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

jbeeko commented 1 year ago

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

xp44mm commented 12 months ago

just copy & paste:

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

foo 0;;

Not bad either!

jwosty commented 12 months ago

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.