Meaning of [||]

Hi,

I was just reading through the Falco frameworks getting started page which has the code snippet:

module HelloWorld.Program

open Falco
open Falco.Routing
open Falco.HostBuilder

webHost [||] {
    endpoints [
        get "/" (Response.ofPlainText "Hello World")
    ]
}

What does the [||] notation mean?

Thank you!

Hi @flx,

[||] is the way of defining an empty “array” literal, in the same way as [] is the way of defining an empty “list” literal. You could define an array with elements in it such as [| 1 .. 5 |] or [| "hello"; "world" |]. Arrays in F# are another list-like structure that just has different performance characteristics, so sometimes they’re used in place of lists to speed things up. You can see the difference in performance here

2 Likes

I would suggest that arrays are more significantly different to lists than just being list-like with different performance characteristics!

An array is a fixed size and the elements can be modified in place, this is very different to a list.

let arr = [|1; 2; 3|]
arr[1] <- 42

Is something you just cannot do with a regular F# list without iterating through the list and building at least partially a new one.