-
Notifications
You must be signed in to change notification settings - Fork 0
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
Could we try to start this project in F#? #4
Comments
Although I love F# too, I believe immutable-as-possible C# is right choice for the project. I am deeply convinced that libraries with base functionality should be accessible by as many contributors as possible. It also would be good to avoid additional dependencies like But let's talk about possible F# design first.
|
Regardless of language, we should insist on:
Extensibility: The Atom tree structure should be completely enumerated, regardless of language. The function which renders it needs to enumerate the possibilities to do its job. This makes things much cleaner, but requires an explicit mechanism for extensibility if that is needed. Perhaps a user defined parser element, Atom DU case, and rendering function step, activated by additing to a dictionary. C#-friendly F#
Cons of F#
Pros of F#
Non-cons of F#
Regardless of language part 2This project starts with the Atom type. We can continue to model it in F# which should be easy to understand even to people who don't know F#. Converting the Atom to and from C# is easy. It's just a stretch with scale factor 4 and 1/4 respectively in the y direction 😊 . |
@ForNeVeR Re: Extensibility @charlesroddie //Declaration
[DiscriminatedUnionAttribute]
public class SomeDU
{
public class Case1 : SomeDU
{
public int Field { get; }
public Case1(int field) => Field = field;
}
public class Case2 : SomeDU
{
public float Field1 { get; }
public object Field2 { get; }
public Case1(float field1) => (Field1, Field2) = (field1, field2);
}
}
//Usage
SomeDU du = ...;
switch(du)
{
case SomeDU.Case1 case1:
DoStuff(case1);
break;
case SomeDU.Case2 case2:
DoStuff(case2);
break;
}
You could trade width for height, depends on your preference. For the other stuff, I agree with for now, especially with @gsomix. |
I haven't worked enough with F# to be particularly helpful. What I will say about C# is that I find it annoying that one can't initialize immutable objects this way:
That setting inside the curly braces is considered "mutation", rather than "part of the constructor." But I think that's an annoyance, not a major factor in a language choice. |
@verybadcat quick notes on your case: I agree that it's annoying. In F# this syntax will work: let foo: ImmutableObject = { // you may actually omit the `ImmutableObject` here
Field1 = "Bar"
Field2 = 10
} In C#, a similar construct is probably not so bad: var foo = ImmutableObject.Create(
field1: "Bar",
field2: 10
); |
Summarizing why not to use F#...
Well, that's a short list. I'm now motivated to actually learn F# (I was only able to read but not write F# before). Green flag for F#. |
I don't think .Net Standard support is related. The latest F# requires .Net Standard 1.6 and that is very conservative. I would just go with .Net Standard 2.0 for our library, which is highly compatible, is the standard standard version, has all the features (except new .net core stuff like span), and will remain usable for a long time. |
Span and related APIs will be added in .NET Standard 2.1. Maybe we will upgrade to it once it is released. |
Ah, yeah, it seems like I've finally eliminated need in that particular method. But I have Here's where it's defined: And here's one of the implementations: |
Regarding .NET Standard stuff: I don't think that 1.x support is very relevant. It looks like .NET Standard 2.0 is better in all regards, and (almost?) every use case that supported 1.x supports 2.0 now. AFAIK, That means we could create our own Although, the .NET classes from the standard library doesn't support too much of I don't think that TL;DR:
Later we could discuss if we want to migrate to .NET Standard 2.1 or maybe introduce conditional compilation to create blazing fast algorithms for .NET Core while keeping compatibility with .NET Framework's old ways. |
And, yeah, in conclusion about the topic: @Happypig375 do you think we should write MathAtom in C#? |
@ForNeVeR Sorry for forgetting this issue. |
Alright, I think we have a consensus here. I'll try to keep a close eye on C# compatibility and add some useful (automated) compat checks down the road. |
So, let's start coding? :) Please, create issues, I would be glad to work on some in my spare time. |
I will need to finish off verybadcat/CSharpMath#11 before CSharpMath can change its atom structure dramatically, as porting MathEditor relies on the original atom structure. That said, @gsomix you can start on this independently for now. |
Good plan. If there are implications for the Atom type please post here. |
The time has come.
I suggest we could try to write this project in F#. Here're my arguments.
Pros
Cons
Open questions
SourceSpan
orStyle
). Each of my structures hasSourceSpan
property, so I had to essentially implement the same stupid methodWithSourceSpan(SourceSpan ss) => this.Clone(ss: ss)
many times. We should think well about composability issues here (how should we compose the atoms, how could we implement typical workflow of CSharpMath or WPF-Math atom builder here)Atom
s and it would (hopefully) work well. But in F#, we have these options:General thoughts
It we're going to follow the F# route, we'll need to establish an uncommonly (for F#-based projects, I mean) C#-friendly environment:
<PackageReference>
tooling will save us from major headaches, but still: I insist that we need to check that regularly and systematically as part of our CIClosing
@verybadcat, @alexreg I would appreciate your input very much, because I think you're much less biased towards F# than e.g. myself, @Happypig375, @charlesroddie or @gsomix.
Others: please also participate in the discussion, I appreciate your input as well :)
The text was updated successfully, but these errors were encountered: