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

F# 9 nullability migration #622

Open
xperiandri opened this issue Jan 8, 2025 · 6 comments
Open

F# 9 nullability migration #622

xperiandri opened this issue Jan 8, 2025 · 6 comments

Comments

@xperiandri
Copy link

High-level description
I've migrated my code to F# 9 compiler and nullability support

Expected or desired behavior
You can pick my changes if you want the same migration
Ecierge/Elmish.Uno#1

Additional Information
The other question is should we restrict a model and a message on a view model to be non-null?

type DynamicViewModel<'model, 'msg when 'model : not null and 'msg : not null>
      ( args: ViewModelArgs<'model, 'msg>,
        bindings: Binding<'model, 'msg> list)
type ViewModelBase<'model, 'msg when 'model : not null and 'msg : not null>(args: ViewModelArgs<'model, 'msg>)

https://github.com/Ecierge/Elmish.Uno/blob/be64c50b6b7cca1ac774704145e09fd17ee4cf3f/src/Elmish.Uno/ViewModels.fs#L143
https://github.com/Ecierge/Elmish.Uno/blob/be64c50b6b7cca1ac774704145e09fd17ee4cf3f/src/Elmish.Uno/ViewModels.fs#L359

@xperiandri
Copy link
Author

@TysonMN @marner2 @YkTru your thoughts?

@TysonMN
Copy link
Member

TysonMN commented Jan 22, 2025

I expect most things should be not null. Maybe everything.

Do you want to contribute a PR with this change?

@YkTru
Copy link

YkTru commented Jan 25, 2025

Just to clarify, when you ask:

The other question is should we restrict a model and a message on a view model to be non-null?

Is the primary benefit of F# 9 in this context limited to getting compiler warnings and clearer communication of the API intent? Are there additional advantages beyond these?

I think opening a PR would be relevant too

@xperiandri
Copy link
Author

The main feature is nullable reference types same as in C# that allows to propagate that from .NET SDK and other libraries to F# code

@YkTru
Copy link

YkTru commented Jan 29, 2025

Yes, I understand that. However, I'm wondering what additional benefits this approach provides compared to Option.ofObj or box f = null, aside from improved syntax, clearer intent, and compiler warnings.

Personnally, the main nullability issue I face with static VM is with SubModelSelectedItem, especially in recursive data structures. It often fails to find the member collection's name due to the stringly-typed parameter and the lack of compiler support. Additionally, it must reference a ViewModel instance that may not exist at the time of access.

Do you think using a Nullable type could help with these core issues? I feel like SubModelSelectedItem helper should be completely redesigned from the ground up, if possible.

@YkTru
Copy link

YkTru commented Feb 9, 2025

@xperiandri, could you open a PR, please? It's been a while since the library was last updated, and this one seems relevant. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants