Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3488418
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:16:06+00:00 2026-05-18T11:16:06+00:00

type SQLConn = val mutable private connection : string option member this.Connection with get()

  • 0
type SQLConn =
    val mutable private connection  : string option

    member this.Connection
        with get() : string   = this.connection.Value
        and  set(v)           = this.connection           <- Some v

    new (connection : string) = {connection = Some connection;}
    new() = SQLConn @"Data Source=D:\Projects\AL\Service\ncFlow\dbase\dbflow.db3; Version=3;Password=432432434324"

I want to use “let x = 5+5” there or something like that, so how can I use private functions in my type (class) (record) , I know that I can use them if I do SQLConn() , but then I can’t use val, I want to use both : val and let …

thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:16:06+00:00Added an answer on May 18, 2026 at 11:16 am

    As Tim explains, you can only use local let bindings with the implicit constructor syntax. I would definitely follow this approach as it makes F# code more readable.

    Do you have any particular reason why you also want to use val in your code? You can still use them with the implicit constructor syntax, but they have to be mutable and initialized using mutation:

    type SQLConn(connection:string) as x = 
      let mutable connection = connection
    
      // Declare field using 'val' declaration (has to be mutable)
      [<DefaultValue>]
      val mutable a : int 
    
      // Initialize the value imperatively in constructor
      do x.a <- 10
    
      member this.Connection 
        with get() = connection and set(v) = connection <- v 
    
      new() = SQLConn @"Data Source=.." 
    

    As far as I can tell val is only needed to create fields that are not private (which may be required by some code-gen based tools like ASP.NET, but is otherwise not really useful).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

type Foo = class inherit Bar val _stuff : int new (stuff : int)
Type.GetType(System.String) Is there a lookup for the aliases available somewhere? Type.GetType(string) returns null .
I type ArrayList memberNames = new ArrayList() { Jim, John, George }; and Visual
Consider type like this one public interface IHaveGenericMethod { T1 Method<T1>(T1 parm); T2 Method<T1,T2>(T1
Is this valid ? def CallableStatement st try { ... st = sqlConn.prepareCall(call....) ...
Which type of input is least vulnerable to Cross-Site Scripting (XSS) and SQL Injection
What type of authentication would you suggest for the service that is: implemented as
Is type checking considered bad practice even if you are checking against an interface?
Given a handle of type HWND is it possible to confirm that the handle
The following returns Type of conditional expression cannot be determined because there is no

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.