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 728477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:41:10+00:00 2026-05-14T06:41:10+00:00

I decided to port the class in C# below to F# as an exercise.

  • 0

I decided to port the class in C# below to F# as an exercise.

It was difficult. I only notice three problems

1) Greet is visible
2) I can not get v to be a static class variable
3) I do not know how to set the greet member in the constructor.

How do i fix these? The code should be similar enough that i do not need to change any C# source. ATM only Test1.v = 21; does not work

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CsFsTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Test1.hi("stu");
            new Test1().hi();
            Test1.v = 21;
            var a = new Test1("Stan");
            a.hi();
            a.a = 9;

            Console.WriteLine("v = {0} {1} {2}", a.a, a.b, a.NotSTATIC());
        }
    }
    class Test1
    {
        public int a;
        public int b { get { return a * 2; } }
        string greet = "User";
        public static int v;

        public Test1() {}
        public Test1(string name) { greet = name; }

        public static void hi(string greet) { Console.WriteLine("Hi {0}", greet); }
        public void hi() { Console.WriteLine("Hi {0} #{1}", greet, v); }
        public int NotSTATIC() { return v; }
    }
}

F#

namespace CsFsTest

type Test1 = 
    (*
        public int a;
        public int b { get { return a * 2; } }
        string greet = "User";
        public static int v;
    *)
    [<DefaultValue>]
    val mutable a : int
    member x.b = x.a * 2
    member x.greet = "User" (*!! Needs to be private *)

    [<DefaultValue>]
    val mutable v : int (*!! Needs to be static *)

    (*
        public Test1() {}
        public Test1(string name) { greet = name; }
    *)
    new () = {}
    new (name) = { }

    (*  
        public static void hi(string greet) { Console.WriteLine("Hi {0}", greet); }
        public void hi() { Console.WriteLine("Hi {0} #{1}", greet, v); }
        public int NotSTATIC() { return v; }
    *)   
    static member hi(greet) = 
        printfn "hi %s" greet
    member x.hi() =
        printfn "hi %s #%i" x.greet x.v
    member x.NotSTATIC() =
        x.v
  • 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-14T06:41:10+00:00Added an answer on May 14, 2026 at 6:41 am

    Below is some F# that compiles against the C# client.

    In .NET, one very rarely exposes public fields; I would recommend against it. The F# syntax for exposing fields is somewhat cumbersome.

    namespace CsFsTest
    
    open System
    
    type Test1 =
        val mutable private greet : string
        [<DefaultValue>]
        val mutable public a : int
        [<DefaultValue>]
        static val mutable private vv : int
    
        static member v with get() = Test1.vv 
                        and set(x) = Test1.vv <- x
    
        member this.b = this.a*2
        static member hi(greet:string) = Console.WriteLine("Hi {0}", greet)
        member this.hi() = Console.WriteLine("Hi {0} #{1}", this.greet, Test1.v)
    
        new() = { greet = "User" }
        new(name : string) = { greet = name }
    
        member this.NotSTATIC() = Test1.v
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I decided to have a go at PDO. The function below should move a
I decided not to use an orm and going to use straight ADO.NET for
I've decided to dabble a bit in MonoDroid and MonoTouch and port one of
I'm using Lua and LuaBridge with Allegro 5. I decided to port all graphic
I'm making an Android app using Processing, and have decided to port my code
I recently found out that PHP not only has the fsock* functions, but also
I have to port an application to .NET, so I decided to go with
I am trying to write a port scanner for a security course. I decided
I decided to use PDO after recommends here and i found this code below.
I have a Django application which I decided to port to Google App Engine.

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.