Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide extensions for F# #85

Open
KubaZ2 opened this issue Jan 13, 2025 · 0 comments
Open

Provide extensions for F# #85

KubaZ2 opened this issue Jan 13, 2025 · 0 comments

Comments

@KubaZ2
Copy link
Member

KubaZ2 commented Jan 13, 2025

Description

Here is how you would currently write a minimal API style bot in F#:

let builder = Host.CreateApplicationBuilder()

builder.Services
    .AddApplicationCommands()
    .AddDiscordGateway() |> ignore

let host = builder.Build()

host.AddSlashCommand("ping", "Ping!", Func<string>(fun() -> "Pong"))
    .UseGatewayEventHandlers() |> ignore

host.Run()

Currently, Func<string>(...) is needed for minimal API commands. To improve the experience, it would be needed to provide generic overloads with FSharpFunc<...>. This issue would also be resolved by fsharp/fslang-suggestions#1131.

Of course extensions for services themselves would also be added.

I am also probably unaware of other places in which extensions for F# would be needed. Feel free to suggest them.

The package naming would be {PackageName}.FSharp, so for example it would be NetCord.Hosting.FSharp for NetCord.Hosting.

I think it would be better to write the extensions in F#, as only F# methods can be inlined and optimized by the compiler.

@KubaZ2 KubaZ2 added enhancement New feature or request help wanted labels Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant