Git Product home page Git Product logo

fsharp's Issues

Looking for maintainers!

Hi. I'm C# developer and last month I helped with updating the codebase/CI of the repositories in destructurama org. This repo is the last one among them. I can’t post PRs myself - I have no necessary knowledge and time, but I can continue to help. So if someone is ready to help, I will be glad.

list of lists throws InvalidCastException

Using the test script, I get the an InvalidCastException:

>fsi lists.fsx
System.InvalidCastException: Unable to cast object of type 'Microsoft.FSharp.Collections.FSharpList`1[System.Int32]' to type 'System.Collections.Generic.IEnumerable`1[System.Object]'.
   at Destructurama.FSharp.FSharpTypesDestructuringPolicy.Serilog-Core-IDestructuringPolicy-TryDestructure(Object value, ILogEventPropertyValueFactory propertyValueFactory, LogEventPropertyValue& result) in C:\projects\fsharp\src\Destructurama.FSharp\DestructuramaFSharp.fs:line 31
   at Serilog.Parameters.PropertyValueConverter.CreatePropertyValue(Object value, Destructuring destructuring, Int32 depth) in c:\projects\serilog\src\Serilog\Parameters\PropertyValueConverter-net40.cs:line 121
   at Serilog.Parameters.PropertyValueConverter.DepthLimiter.CreatePropertyValue(Object value, Boolean destructureObjects) in c:\projects\serilog\src\Serilog\Parameters\DepthLimiter.cs:line 45
   at [email protected](b& )
   at Microsoft.FSharp.Collections.IEnumerator.MapEnumerator`1.System-Collections-IEnumerator-MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Serilog.Events.SequenceValue..ctor(IEnumerable`1 elements) in c:\projects\serilog\src\Serilog\Events\SequenceValue-net40.cs:line 37
   at Destructurama.FSharp.FSharpTypesDestructuringPolicy.Serilog-Core-IDestructuringPolicy-TryDestructure(Object value, ILogEventPropertyValueFactory propertyValueFactory, LogEventPropertyValue& result) in C:\projects\fsharp\src\Destructurama.FSharp\DestructuramaFSharp.fs:line 33
   at Serilog.Parameters.PropertyValueConverter.CreatePropertyValue(Object value, Destructuring destructuring, Int32 depth) in c:\projects\serilog\src\Serilog\Parameters\PropertyValueConverter-net40.cs:line 121
   at Serilog.Parameters.PropertyBinder.ConstructProperty(PropertyToken propertyToken, Object value) in c:\projects\serilog\src\Serilog\Parameters\PropertyBinder.cs:line 122
   at Serilog.Parameters.PropertyBinder.ConstructNamedProperties(MessageTemplate template, Object[] messageTemplateParameters) in c:\projects\serilog\src\Serilog\Parameters\PropertyBinder.cs:line 113
   at Serilog.Parameters.PropertyBinder.ConstructProperties(MessageTemplate messageTemplate, Object[] messageTemplateParameters) in c:\projects\serilog\src\Serilog\Parameters\PropertyBinder.cs:line 57
   at Serilog.Core.Pipeline.Logger.Write(LogEventLevel level, Exception exception, String messageTemplate, Object[] propertyValues) in c:\projects\serilog\src\Serilog\Core\Pipeline\Logger.cs:line 138
   at Serilog.Core.Pipeline.Logger.Verbose(String messageTemplate, Object[] propertyValues) in c:\projects\serilog\src\Serilog\Core\Pipeline\Logger.cs:line 177
   at <StartupCode$FSI_0001>.$FSI_0001.main@() in C:\repo\fserilog\serilog.fsx:line 40
Stopped due to error

The test script is:

#I "packages/Serilog/lib/net40"
#r "Serilog"
#r "Serilog.FullNetFx"

#I "packages/Destructurama.FSharp/lib/portable-net45+win+wpa81+wp80+MonoAndroid10+MonoTouch10"
#r "Destructurama.FSharp"

open Serilog

Log.Logger <- LoggerConfiguration()
    .Destructure.FSharpTypes()
    .WriteTo.ColoredConsole()
    .MinimumLevel.Verbose()
    .CreateLogger()

let myListOfLists = [
    [1;2;3;4;5]
    [6;7;8;9;10]
]

Log.Verbose("List of lists {@list}", myListOfLists)

I used the following nuget package versions:

NUGET
  remote: https://nuget.org/api/v2
  specs:
    Destructurama.FSharp (1.0.8)
      Serilog (>= 1.4.204)
    Serilog (1.5.6)

Release version without upper bound on FSharp.Core

The constraint on FSharp.Core was relaxed in PR #13. However, a (non pre-) release has not been created that includes that change. The latest release version available on nuget.org is 1.1.0, which still requires FSharp.Core to have a version strictly less than 4.7.0. The two prereleases on nuget.org after version 1.1.0 are versions 1.1.1-dev-00033 and 1.1.1-dev-00035, and neither includes restricts FSharp.Core from above.

Can a new release of Destructurama.FSharp be made that does not include the upper bound constraint on FSharp.Core?

Weird results for Option, Result, anonymous types

Consider this:

let data = {| Data = "This is a test"; Sub = {| Foo = Ok 1; Bar = [Some 2] |} |}
Log.Information("Data: {@Data}", data)

I get this:

{"Data": "This is a test", "Sub": {"Bar": [{"Value": 2, "$type": "Some"}], "Foo": {"ResultValue": 1, "$type": "Ok"}, "$type": "<>f__AnonymousType2950936943`2"}, "$type": "<>f__AnonymousType2576086083`2"}

There are several issues:

  • "$type": "Some" for Option seems weird
  • "$type": "Ok" for Result seems weird
  • "$type": "<>f__AnonymousType..." should not be there

Ideally, IMHO, for unions, you'd use a format like https://github.com/Tarmil/FSharp.SystemTextJson with union encoding set to

JsonUnionEncoding.Default
||| JsonUnionEncoding.InternalTag
||| JsonUnionEncoding.NamedFields
// And perhaps also this
||| JsonUnionEncoding.UnwrapFieldlessTags

I would therefore want something like this:

{"Data": "This is a test", "Sub": {"Bar": [2], "Foo": {"Case": "Ok", "ResultValue": 1}}}

I understand that this package is old and not actively maintained. I may end up writing my own library to destructure F# types.

Add support for FSharp 5.0

I am having this warning when using C# 5.0:

 warning NU1608: Detected package version outside of dependency constraint: Destructurama.FSharp 1.1.0 requires FSharp.Core (>= 4.6.2 && < 4.7.0) but version FSharp.Core 5.0.0 was resolved

But everything seems to be working fine.

Can the upper bound constraint be bumped?

Add project URL

I think the NuGet package does not include a project URL (that links back to this repo).

Built-in Result type not destructured

The FSharp.Core built-in Result type (defined here) is not destructured correctly:

Microsoft.FSharp.Core.FSharpResult`2[System.String,System.Object]

It seems it only runs ToString on it. I would expect this to be destructured the same way as other unions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.