resharper-fsharp icon indicating copy to clipboard operation
resharper-fsharp copied to clipboard

Idris-style case split code generation

Open ieviev opened this issue 3 years ago • 7 comments

i've recently looked into a lot of academic research languages and i found something that'd be very cool to have in F# as well.

the idea is to have an action on a discriminated union value that creates all the available cases like this.

case split

basically i want to implement the same thing, but i was hoping someone would help me out with this. since filling in a single discriminated union is already implemented it shouldn't be much of a leap right?

ieviev avatar Dec 08 '22 21:12 ieviev

plus what would be even more beneficial is generating match cases for OO hierarchies,

so in this C# AST example i could generate all possible implementations of the CSharpSyntaxNode abstract class

image

ieviev avatar Dec 08 '22 21:12 ieviev

and of course interface hierarchies as well. i think it'd save a lot of time

ieviev avatar Dec 08 '22 21:12 ieviev

@aciq I've been working on this for the last few days, and here's where it was in the noon:

generateMatch04

And I was working on the union cases just this evening, but there's no gif yet 🙂

There're a few things that I was going to implement separately, and I can keep some of them for you to implement if you wish 🙂

auduchinok avatar Dec 08 '22 21:12 auduchinok

@auduchinok ok that is awesome

yeah i'll gladly help out with this

but one thing - is it possible to disable renaming the template holes when deconstructing tuples or filling in unions? i find the default names fine most of the time.

ieviev avatar Dec 08 '22 21:12 ieviev

IIRC, there was this in VS F# PowerTools:

https://github.com/fsprojects-archive/zzarchive-VisualFSharpPowerTools/blob/e928448af203713f67aae92ea4f45e88d49487eb/src/FSharp.Editing.VisualStudio/CodeGeneration/UnionPatternMatchCaseGeneratorSmartTagger.fs

maybe good to look at, depending how far you are @auduchinok?

smoothdeveloper avatar Dec 08 '22 22:12 smoothdeveloper

maybe good to look at, depending how far you are @auduchinok?

@smoothdeveloper Thanks for the pointer! I've checked it, and it seems it's not going to help in any way 🙂

auduchinok avatar Dec 09 '22 11:12 auduchinok

but one thing - is it possible to disable renaming the template holes when deconstructing tuples or filling in unions? i find the default names fine most of the time.

Sure. It wouldn't make sense to do it when generating many patterns

auduchinok avatar Dec 09 '22 11:12 auduchinok