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

F# Spec doesn't mention private representation Discriminated unions #321

Open
ovatsus opened this issue Oct 14, 2014 · 3 comments
Open

F# Spec doesn't mention private representation Discriminated unions #321

ovatsus opened this issue Oct 14, 2014 · 3 comments

Comments

@ovatsus
Copy link
Member

ovatsus commented Oct 14, 2014

For example, in this type:

  type HtmlAttribute = 
      private | HtmlAttribute of name:string * value:string    

What's the effect that private should have? I see that in C# projects, I no longer have the NewHtmlAttribute constructor, but I can keep doing pattern matching and create new values with HtmlAttribute("a", "b") in F#. Is that the intended behaviour? I was expecting to not be able to create new values using the union case constructor, and force people to use a static method that normalizes the arguments

@Rickasaurus
Copy link
Contributor

Just thinking out loud, it would be nice if we could expose an API over DUs for consumption from C# so that if we want to change the representation somehow (like support for GADTs) it wouldn't be as much of an issue.

@ovatsus
Copy link
Member Author

ovatsus commented Oct 14, 2014

Actually, the case constructor is only available inside the current project, not outside, so this seem like a bug

@dsyme
Copy link
Contributor

dsyme commented Oct 15, 2014

The meaning is "private to the enclosing module or namespace fragment and internal to the assembly". So this correctly gives an error:

module M = 
    type HtmlAttribute = 
          private | HtmlAttribute of name:string * value:string    

let x = M.HtmlAttribute("","")

let f x = 
    match x with 
    | M.HtmlAttribute(a,b) -> a + b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants