Friday, January 25, 2019

Parser written in F# used in .NET Standard?

I’m curious if this is even possible before I head down the road of attempting this...

I’d like to write a generic command line argument parser to use as a shared library between many C# .NET projects; both Framework 472 and Core 21. I want something where I can specify a valid set of verbs, options, etc in my Main() method in the console app, and then parse args[] into something more useful than a string array.

Today I started writing the parser in a C# .NET Standard library and created a working prototype, but wasn’t really happy with it. Then I remember my days learning Haskell and other functional languages at university with projects related to parsing and got to thinking... I could probably write a parser in F#, and it would probably be faster, shorter, and cleaner. I don’t have any F# experience, but I should be able to pick it up fairly quickly (and have been interested in learning it anyways), so this isn’t a concern for me.

My question is, how does interop between C# and F# work? Will I be able to write a parser in F# that I can reference in a C# .Net Standard library to parse a string[] into some C# type that I can then use in other .NET Console apps?

Any one done something like this? Any tips?

Parser written in F# used in .NET Standard? Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team