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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:47:18+00:00 2026-05-13T20:47:18+00:00

What does x :: xs’ mean? I dont have much functional experience but IIRC

  • 0

What doesx :: xs' mean?
I dont have much functional experience but IIRC in F# 1 :: 2 :: 3 :: [];; creates an array of [1,2,3]
so what does the ‘ do?

let rec sum xs =
  match xs with
    | [] -> 0
    | x :: xs' -> x + sum xs'
  • 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-13T20:47:18+00:00Added an answer on May 13, 2026 at 8:47 pm

    I think sepp2k already answered most of the question, but I’d like to add a couple of points that may clarify how F#/OCaml compiler interprets the code and explain some common uses.

    Regarding the ' symbol – this is just a part of a name (a valid identifier starts with a letter and then contains one or more letters, numbers or ' symbols). It is usually used if you have a function or value that is very similar to some other, but is in some way new or modified.

    • In your example, xs is a list that should be summed and the pattern matching decomposes the list and gives you a new list (without the first element) that you need to sum, so it is called xs'

    • Another frequent use is when declaring a local utility function that implements the functionality and takes an additional parameter (typically, when writing tail-recursive code):

      let sum list =
        let rec sum' list res = 
          match list with
          | [] -> res
          | x::xs -> sum' xs (res + x)
        sum' list 0
      

    However, I think there is usually a better name for the function/value, so I try to avoid using ' when writing code (I think it isn’t particularly readable and moreover, it doesn’t colorize correctly on StackOverflow!)

    Regarding the :: symbol – as already mentioned, it is used to create lists from a single element and a list (1::[2;3] creates a list [1;2;3]). It is however worth noting that the symbol can be used in two different ways and it is also interpreted in two different ways by the compiler.

    When creating a list, you use it as an operator that constructs a list (just like when you use + to add two numbers). However, when you use it in the match construct, it is used as a pattern, which is a different syntactic category – the pattern is used to decompose the list into an element and the remainder and it succeeds for any non-empty list:

    // operator
    let x = 0
    let xs = [1;2;3]
    let list = x::xs
    
    // pattern
    match list with
    | y::ys -> // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have any experience with the two latest revisions of Redmine? I am
Does COUNT(*) have any significant impact for MySQL performance if query already has GROUP
Does anyone have a translate function for x/y positions after rotation in javascript? for
Does anyone know why UsernameExists wont return True. I must have my syntax messed
Does any one have a solution to make the SpecFlow autocomplete in Visual Studio
Does anyone know of a Mootools script that provides nested sortable but also works
Does anyone have any suggestions for the best / simplest way to view all
Does OpenJPA have any support for batch insert similar to Hibernate ? I haven't
Does the AppleWWDRCA.cer have any bearing on developing certificates using OpenSSL? If so, what?
Does anyone know how to add a border to a Dockpanel. i have this:

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.