Getting Started with F# on a Mac using the Windows 10 Preview

In preparation for my talk at LambdaConf, I wanted to be able to develop in F# on my Mac. There wasn’t a super easy guide that explained everything I needed to do, so I thought I’d write one. (I don’t claim to be an expert in F# or Windows development, but these are the steps that worked for me.)

I’d heard about .NET being made available for Mac and Linux, but they are still in preview mode. I suspected that the best development experience would be on Windows. (That said, if you aren’t interested in putting up with prerelease software rough edges in exchange for the adrenaline rush of being an early adopter, Windows 10 Technical Preview is not for you right now.)

Getting started with Windows 10 on a Mac is easy. First, download VirtualBox. Then, join the Windows Insider program to download the Windows 10 preview ISO.

Create a Windows 10 virtual machine in VirtualBox. Allocate as much RAM, HDD space, and CPUs as you can. (This probably should have been obvious to me, but I was trying to multitask and I launched multiple VMs at once, each of which had about 70% of my machine’s RAM and CPUs, so I was asking my machine for 140% of the RAM it had and CPUs, plus of course what it was running for itself. This did not end well haha.) Try to add at least more than one CPU; if you don’t, the Windows UI will be clunky to use as it keeps freezing up without the ability to have the UI on one CPU and background tasks on others.

With your virtual machine selected, go to Settings > Storage and click the disk with a + on it by “Controller: IDE”. This simulates the disc drive for your machine. Choose the Windows 10 ISO you downloaded.

Boot your machine. Windows will walk you through the set-up steps.

When it is complete, the machine will restart, and you’ll be back to this screen:

Do not go through the install workflow again. Windows will just keep installing additional copies of itself each time you do. Instead, we will just remove the ISO to tell Windows that we are not trying to boot from that image any more.

Go back to Settings > Storage and remove the ISO. I didn’t realize I needed to do this originally, and I kept restarting the box, and installing Windows again each time. With the ISO removed, Windows will boot normally.

You’ll now have a few more set-up steps to walk through. Once you get to the desktop, you’ll probably be wanting to increase the resolution. Go back to “Storage > Settings” in VirtualBox and add another ISO to the disk drive. This time, you will choose “empty”, to give the VM a place where the guest additions can be added. Then, go to “Devices > Insert Guest Additions CD image” on VirtualBox’s top menu. Back in the VM, choose to run the executable on the inserted CD.

When this is complete, and you’ve restarted your machine, go to “View > Switch to Seamless mode” on VirtualBox’s top menu. (It may be greyed out until a few seconds after you log in.) Now things should be looking nicer.

Launch Project Spartan and go to Visual Studio 2015 Community Edition. Download the installer and run it.

When the installer is complete, launch VS. Choose “F#” as your default project type. Create a new F# project. Hit F5 to build and run your project, and you’ll see code running!

To get tests, you need to install a test framework, and a test adapter so Visual Studio knows how to find your tests. I did this via the NuGet package manager console. (There’s also a UI, and the two are supposed to be functionally equivalent, but the UI didn’t work for me.)

Go to the Package Manager Console, and set “Package Source” to api.nuget.org.

Run the following:

Other test frameworks should work as well. This is just what worked for me.

Create a new test file, by clicking “Add > New Item > F# source file” in the Solution Explorer.

Now paste in the following tests:

Go to “Devices > Shared Clipboard > Bidirectional” to share your clipboard between the host and Windows.

In Visual Studio, go to “Test > Run > All Tests”. You will see a test failing and a test passing, as expected. You are now set to start developing F#. Enjoy!