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

Struct representations for active patterns limitations #12389

Closed
kevmal opened this issue Nov 15, 2021 · 6 comments
Closed

Struct representations for active patterns limitations #12389

kevmal opened this issue Nov 15, 2021 · 6 comments

Comments

@kevmal
Copy link
Contributor

kevmal commented Nov 15, 2021

I would expect to be able to simply switch an existing active pattern to use structs but it seems limited. Any reason for restricting use to top level active patterns? Would be nice to be able to do the following:

let f1() = 
    [<return: Struct>]
    let (|AP|_|) (x : int) = 
         ...
    ...

or

let f2 ([<return: Struct>] ``|AP|_|``) = 
    ...
@Happypig375
Copy link
Member

The first one is fsharp/fslang-suggestions#848 while the second one can already be done:

let f2 ((|AP|_|): _ -> _ voption) = 
    match 1 with AP 1 -> 1 | _ -> 2

@kevmal
Copy link
Contributor Author

kevmal commented Nov 15, 2021

It's great that f2 works, and it's actually preferable to an attribute but it seems a bit inconsistent... I can (and probably will) do

let f1() = 
    match 
        (fun x -> 
            if x > 100 then 
                ValueSome 1 
            else 
                ValueNone
        ) with 
    | ``|AP|_|`` ->
    match 1 with AP 1 -> 1 | _ -> 2

yet a simple let binding would give an error.

@dsyme
Copy link
Contributor

dsyme commented Nov 15, 2021

I'll close this per @Happypig375's comment #12389 (comment)

@dsyme dsyme closed this as completed Nov 15, 2021
@Happypig375
Copy link
Member

@kevmal

let f1() =
    fun x ->
        if x > 100 then 
            ValueSome 1 
        else 
            ValueNone
    |> fun (|AP|_|) ->
    match 1 with AP 1 -> 1 | _ -> 2

@kevmal
Copy link
Contributor Author

kevmal commented Nov 15, 2021

@dsyme Does that mean fsharp/fslang-suggestions#848 is approved?

@dsyme
Copy link
Contributor

dsyme commented Nov 16, 2021

Ah my mistake, I thought the link was referring to the idea of simply inferring structness from return type here fsharp/fslang-suggestions#1041 (comment)

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

3 participants