F# Tip Of The Week (14 October 2013)

It is possible to declare a list or an array without the separating semicolons by declaring each element on a separate line.  Like this:

let favoriteBreeds = [
    "Antwerp"
    "Carneaux"
    "Swiss Mondaine"
]

//Array

let favoriteBreedsArray = [|
    "Antwerp"
    "Carneaux"
    "Swiss Mondaine"
|]

Note: for reasons I confess are unclear to me, the first member of the list/array must be on the next line from the opening symbol of the collection. Well, to be precise (this is software development after all) this is true of arrays–the same is not true of lists. But since putting the first element of the array on the next line works in both cases, it’s simplest just to do it this way.

EDIT: Per Dave Thomas, you can put the first element of the collection on the same line as the opening symbol; you just need to insure that you align all of the other elements, DIRECTLY beneath the first element, as in this code gist which Dave put up.

Personally I consider it’s easier to simply stick to the convention of always putting the first element on the next line so you don’t have to worry that much about the alignment but this does work.

 

One response

  1. Pingback: F# Weekly #41, 2013 | Sergey Tihon's Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: