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

C# to F# Lambda and interoperability #4470

Closed
roozbehid opened this issue Mar 8, 2018 · 3 comments
Closed

C# to F# Lambda and interoperability #4470

roozbehid opened this issue Mar 8, 2018 · 3 comments

Comments

@roozbehid
Copy link

roozbehid commented Mar 8, 2018

I am trying to use Deedle package in C# and it seems it is written mostly in F# and last update was in 2016.
I came around to this function

    //
    // Summary:
    //     Performs sampling by time and aggregates chunks obtained by time-sampling into
    //     a single value using a specified function. The operation generates keys starting
    //     at the first key in the source series, using the specified `interval` and then
    //     obtains chunks based on these keys in a fashion similar to the `Series.resample`
    //     function. ## Parameters - `series` - An input series to be resampled - `interval`
    //     - The interval between the individual samples - `dir` - If this parameter is
    //     `Direction.Forward`, then each key is used as the smallest key in a chunk; for
    //     `Direction.Backward`, the keys are used as the greatest keys in a chunk. - `aggregate`
    //     - A function that is called to aggregate each chunk into a single value. ## Remarks
    //     This operation is only supported on ordered series. The method throws `InvalidOperationException`
    //     when the series is not ordered. [category:Lookup, resampling and scaling]
    public static Series<DateTime, object> SampleInto<V>(this Series<DateTime, V> series, TimeSpan interval, Direction dir, Func<DateTime, FSharpFunc<Series<DateTime, V>, object>> aggregate);

and I could not in any way make aggregate work! This is the only logical one I can think of :

        var rows_en = Enumerable.Range(1,10).Select(i =>
        {
            var sb = new SeriesBuilder<string>();
            sb.Add("Date", DateTime.Now.AddHours(i));
            return KeyValue.Create(i, sb.Series);
        }
        );
        var df = Frame.FromRows(rows_en);
        var df2 = df.IndexRows<DateTime>("Date").SortRowsByKey();
        df2.Rows.SampleInto(TimeSpan.FromHours(0.5),Direction.Backward, (a) => {
            return FuncConvert.ToFSharpFunc<Series<DateTime, ObjectSeries<string>>>( (V) => { ; });
        }).Print();

But researching problem in internet I also came to #1254 which mentioned following syntaxes as working :

Converter<int, int> func = x => x + 1;
FSharpFunc<int, int> fsfunc = func;

error is

Error CS0029 Cannot implicitly convert type 'System.Converter<int, int>' to Microsoft.FSharp.Core.FSharpFunc<int, int>'	

and also mentioned this one should work

FSharpFunc<int, int> func = (Converter<int,int>)(x => x + 1);

and error is same as before.

I am using a .Net Core 2.0 and C# 7.2

@dsyme
Copy link
Contributor

dsyme commented Mar 9, 2018

@roozbehid This is because of #1847. I'll close this and track it there

BTW has Deedle been updated to use .NET Standard? I'd expect it would need to be. That doesn't solve your issue though.

@roozbehid
Copy link
Author

@dsyme it is not updated. but you can reference any full .net from .net core and it should work.
I solved my problem by referencing v3 fsharp core files. But obviously there is a problem.

@cartermp
Copy link
Contributor

Closing as duplicate of #1874

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