Skip to content

Conversation

@WhiteBlackGoose
Copy link
Collaborator

@WhiteBlackGoose WhiteBlackGoose commented Aug 28, 2021

Usage:

F#

Simple

let obj1 =
    ImmutableDynamicObj ()
    ++ ("aaa", 5)
    ++ ("bbb", "ccc")
    -- "aaa"

(obj1 is of type ImmutableDynamicObj)

With inheritance

type Quack (map) =
    inherit ImmutableDynamicObj (map)

    new() = Quack (Map.empty)

...

let obj1 =
    Quack ()
    ++ ("aaa", 5)
    -- "aaa"
    ++ ("bbb", 5)

(obj1 is of type Quack)

C#

Simple

var obj1 =
    new ImmutableDynamicObj()
    .With("aa", 4)
    .With("bb", 10)
    .Without("aa")
    ;

(obj1 is of type ImmutableDynamicObj)

With inheritance

public class MyDynamicObject : ImmutableDynamicObj
{
    public MyDynamicObject(FSharpMap<string, object> map) : base(map) { }
    public MyDynamicObject() : base(new(Enumerable.Empty<Tuple<string, object>>())) { }
}

...

var obj1 =
    new MyDynamicObject()
    .With("aaa", 5);

(obj1 is of type MyDynamicObject)

@WhiteBlackGoose WhiteBlackGoose marked this pull request as draft August 28, 2021 19:33
@WhiteBlackGoose WhiteBlackGoose marked this pull request as ready for review August 29, 2021 13:53
@WhiteBlackGoose
Copy link
Collaborator Author

There should also be added CSharpTests.csproj to testing in CI

Instead of relfection and SRTP, we constrain the inherited type to new() and after creation mutate its private field. No inline members needed, now all logic reside in assembly.
@WhiteBlackGoose WhiteBlackGoose marked this pull request as draft August 29, 2021 17:51
@WhiteBlackGoose
Copy link
Collaborator Author

WhiteBlackGoose commented Aug 29, 2021

Questions to resolve:

  • Naming for With and Without (as proposed by @gsomix, it may be add and remove)
  • Operators for those methods (as instead of ++ and --, if needed)
  • C# naming for With and Without (in C# they're extension methods)
  • Is it ok that we require the inheritor to have a paramless constructor? (that allowed for a very clean CLS-compliant solution, but there still is another way)
  • ...

@kMutagene
Copy link
Member

Naming for With and Without (as proposed by @gsomix, it may be add and remove)

Agreed on add/remove, maybe a bit more verbose addItem / removeItem? although the in F# core API for Map it is just add, so i guess thats canon and we should go for that.

C# naming for With and Without (in C# they're extension methods)

Here i would go for AddItem / RemoveItem or WithItem / WithoutItem, but you know better what C# users would expect from a fluent API so choose whatever you think fits best. When you choose AddItem it might be worth to use addItem in F# as well for consistency.

Copy link
Member

@kMutagene kMutagene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work. My comments are really minor ones, good stuff 💯

# Visual Studio Version 16
VisualStudioVersion = 16.0.31515.178
# Visual Studio Version 17
VisualStudioVersion = 17.0.31521.260
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this has any effect, but this is from VS Preview right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I will revert it once we understand that everything else is good enough

@kMutagene kMutagene marked this pull request as ready for review September 3, 2021 15:58
@kMutagene kMutagene merged commit abcc9a8 into CSBiology:main Sep 3, 2021
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

Successfully merging this pull request may close these issues.

2 participants