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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:24:41+00:00 2026-05-21T00:24:41+00:00

Sorry for the vague description, couldn’t find a better way to plain it. I’m

  • 0

Sorry for the vague description, couldn’t find a better way to plain it.

I’m starting with F# and like many others I’m translating my solved Euler problems to F#. I like to run my code using tests and also I like the FsUnit style. With the help of the given example I did this:

open System
open NUnit.Framework
open FsUnit

type EulerProblem() =
    member this.problem1 = Seq.init 999 (fun n -> n + 1)
                             |> Seq.filter (fun n -> n % 3 = 0 || n % 5 = 0)
                             |> Seq.sum

[<TestFixture>]
type ``Given an Euler problem`` () =
    let euler = new EulerProblem()

    [<Test>] member test.
        ``when I try to solve #1 should return [the magic number]`` ()=           
            euler.problem1 |> should equal [the magic number]

This works, but I cannot understand what the period after the test method does. If I take it away the compiler complaints saying:

This instance member needs a parameter to represent the object being invoked. Make the member static or use the notation ‘member x.Member(args)

Sorry if this is trivial, and maybe i’m not using the correct wording but couldn’t get an answer with google.

Thanks

  • 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-21T00:24:41+00:00Added an answer on May 21, 2026 at 12:24 am

    If you are familiar with C#, or Java, or C++, you can refer to a class instance using the this reserved word within instance members. In F#, you must explicitly give a name to the class instance for each member definition and in the FsUnit example, the name given is merely test but it’s not actually used. You could just the same have written the test method as

    [<Test>] member this.
        ``when I try to solve #1 should return [the magic number]`` ()=           
            euler.problem1 |> should equal [the magic number]
    

    But note that these days, both xUnit.net and NUnit allow applying their [<Fact>] and [<Test>] attributes respectively for marking tests on let bound functions within modules and without needing TestFixtures and such, which is much better suited for F#. So, for example, the test you gave can and in my opinion ought to be written as:

    module EulerProblemTests () =
        [<Test>]
        let ``when I try to solve #1 should return [the magic number]`` () =           
            let euler = new EulerProblem()  
            euler.problem1 |> should equal [the magic number]
    

    Moreover, you probably don’t want to create your problem solutions as members of a type like EulerProblem, rather as functions within a module.

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

Sidebar

Related Questions

Sorry for the rather vague title, I couldn't think up a better description for
Sorry for the vague description, I can't think of a better way to put
Sorry for the vague title, but I couldn't find an appropriate title, explaining the
Sorry about the vague subject but I couldn't think what to put. Here's my
Sorry for another vague example...but I have a single class where I'm starting a
Sorry for vague question title. I've got a table containing huge list of, say,
Sorry for the vague title, as I really can't explain this problem succinctly. Basically
Sorry about a vague title, but here's what i am trying to do. I
Sorry for the vague question.. but I'm not sure quite what the problem is.
Sorry for the terribly vague title :) I am new to macros and am

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.