FSharpChoice in C#

后端 未结 3 722
别跟我提以往
别跟我提以往 2021-01-05 14:58

I am trying to use FSharpChoice type in a C# project. I have created a choice like so

var a = FSharpChoice.NewChoice1Of3(instofT         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-05 15:27

    I recently started a project to make a "compatibility layer" so that FSharp.Core can be more easily consumed from C#. In particular, it makes generic discriminated unions usable from C#, for example:

    var choice = Choice.New1Of3(100);
    int r = choice.Match(i => i + 21, s => s.Length + 1, s => s.Length + 5);
    

    This does pattern matching on the discriminated union, similarly to how you would do it in F#, except there are no names.

提交回复
热议问题