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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:00:38+00:00 2026-05-13T14:00:38+00:00

So I’ve just about finished my first F# program, with my only functional background

  • 0

So I’ve just about finished my first F# program, with my only functional background being a little bit of knowledge of Haskell (read: Haven’t really produced any programs in it).

After experiencing some boggling behavior, I came to realize that F# makes a differentiation between:

prepareDeck = allSuits |> List.collect generateCards |> shuffle

and

prepareDeck() = allSuits |> List.collect generateCards |> shuffle

I noticed that it “caches” the former, never recalculating it if it’s called again, whereas it treats the latter like a normal function. You can’t tell the difference if the function in question doesn’t have side effects, obviously, but my shuffle did!

Was this supposed to be common knowledge? I haven’t seen it mentioned on any tutorial materials yet. Is the reason just a weakness in the parser, kinda like how you have to declare a function before you use it?

  • 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-13T14:00:39+00:00Added an answer on May 13, 2026 at 2:00 pm

    Most F# material does explain that all top-level statements in a module are executed from top-down on declaration. In other words, what you’ve declared isn’t a function, but a value which is bound once when the program runs.

    It really helps to see the reflected code. I have a simple file:

    let juliet = "awesome"
    let juliet2() = "awesome"
    

    The compiled code looks something like this:

    public static string juliet
    {
        [CompilerGenerated, DebuggerNonUserCode]
        get
        {
            return "awesome";
        }
    }
    
    //...
    
    public static string juliet2()
    {
        return "awesome";
    }
    

    So one is a static property, the other is a function. This is a desirable property, because imagine if we had something like this:

    let x = someLongRunningDatabaseCall()
    

    We only want x to be bound once, we don’t want it to invoke database function everytime we access x.

    Additionally, we can write interesting code like this:

    > let isInNebraska =
        printfn "Creating cities set"
        let cities = set ["Omaha"; "Bellevue"; "Lincoln"; "Papillion"; "La Vista"; "Ralston"]
        fun n -> cities.Contains(n);;
    Creating cities set
    
    val isInNebraska : (string -> bool)
    
    > isInNebraska "Omaha";;
    val it : bool = true
    
    > isInNebraska "Okaloosa";;
    val it : bool = false
    

    Since isInNebraska is a value, its evaluated immediately. It just so happens that its datatype is (string -> bool), so it looks like a function. As a result, we only fill our cities set once even if we invoke the function 1000 times.

    Let’s compare that code to this:

    > let isInNebraska2 n =
        printfn "Creating cities set"
        let cities = set ["Omaha"; "Bellevue"; "Lincoln"; "Papillion"; "La Vista"; "Ralston"]
        cities.Contains(n);;
    
    val isInNebraska2 : string -> bool
    
    > isInNebraska2 "Omaha";;
    Creating cities set
    val it : bool = true
    
    > isInNebraska2 "Okaloosa";;
    Creating cities set
    val it : bool = false
    

    Oops, we’re creating a new cities set everytime we invoke the function.

    So there is definitely a legitimate and real distinction between values and functions.

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

Sidebar

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Put the ribbon tag inside the DockPanel tag before the… May 14, 2026 at 6:04 pm
  • Editorial Team
    Editorial Team added an answer Try this. First establish a class you want to return...… May 14, 2026 at 6:04 pm
  • Editorial Team
    Editorial Team added an answer Yes there have been changes in this Facebook api due… May 14, 2026 at 6:04 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.