Description
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.
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.