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

Improve the pattern matching for IsLikeZip operation in CE #1406

Open
5 of 6 tasks
Shuenhoy opened this issue Feb 7, 2025 · 0 comments
Open
5 of 6 tasks

Improve the pattern matching for IsLikeZip operation in CE #1406

Shuenhoy opened this issue Feb 7, 2025 · 0 comments

Comments

@Shuenhoy
Copy link

Shuenhoy commented Feb 7, 2025

I propose we improve the pattern matching for IsLikeZip operation in CE. Currently, it does support some kinds of pattern matching, but in a very limited way. It can only do pattern matching on one level tuple, and the parentheses cannot be omitted. This is very stange to me, because I cannot find anything in a similar situation in the other parts of the F# language.

As there is very little information about IsLikeZip, eg. what is the behaviors, how to use them, etc., I am not sure if the other structures of pattern matching share the same limations in the old F# version, but only IsLikeZip is forgotten to be upgraded as the language evolving, or it is by design, or it is a bug.

sharplab

open System

type ParamTag<'T> = | ParamTag

type C() =
    [<CustomOperation("ziplike",
                      MaintainsVariableSpaceUsingBind = true,
                      IsLikeZip = true)>]
    member inline __.ZipLike
        (
            (),
            _: ParamTag<'Params>,
            [<InlineIfLambda>] f: unit -> 'Params -> 'Returns
        ) = fun (param: 'Params) -> f () param
    member inline __.For([<InlineIfLambda>] g, [<InlineIfLambda>] f) =
        fun param -> f (g param)
    member inline __.Return (x) = x
    member inline __.Yield(()) = ()
        
        
let c = C()

let param<'Params> () : ParamTag<'Params> = ParamTag

let z = c {
    ziplike a in param<int> () // ok
    return a
}

let z1 = c {
    ziplike (a,b) in param<int*int> () // ok
    return a
}

let z2 = c {
    ziplike (a,b) in param<(int*string)*int> () // ok
    return a
}

let z3 = c {
    ziplike ((a,b),c) in param<(int*string)*int> () // error
    return a
}

let z4 = c {
    ziplike a,b in param<int*int> () // error
    return a
}

The existing way of approaching this problem in F# is using a let in the next line for pattern matching

Pros and Cons

The advantages of making this adjustment to F# are making the language more consistent, making IsLikeZip easier to use.

The disadvantages of making this adjustment to F# are requiring some developments.

Extra information

Estimated cost (XS, S, M, L, XL, XXL): S

Related suggestions: (put links to related suggestions here)

Affidavit (please submit!)

Please tick these items by placing a cross in the box:

  • This is not a question (e.g. like one you might ask on StackOverflow) and I have searched StackOverflow for discussions of this issue
  • This is a language change and not purely a tooling change (e.g. compiler bug, editor support, warning/error messages, new warning, non-breaking optimisation) belonging to the compiler and tooling repository
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this

For Readers

If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.

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

1 participant