CS 3366 Programming Languages
Spring 2015

Computer Science Department
The College of Arts and Sciences
Boston College

About Staff Textbook Grading Resources FSharp.org
Library Piazza Schedule Canvas Problem Sets

FSharp Installation Guide

As you probably already know, Fsharp is a dialect of the ML Programming Language. ML is well-suited for working with programming languages. The F# dialect is designed to run on the .Net virtual machine which is a Windows-based VM. This document details some steps that can be carried out to get F# running on a Mac running OS X.

F# on Windows

If you're using a Windows system you can take advantage of Microsoft's Dreamspark program which gives Visual Studio away for free to students. Visual Studio comes with F# and tools built-in.

If you have questions about how to install Visual Studio on your Windows machine, it might be worthwhile posting them on the course Piazza website. If you have experience with installing Visual Studio, please share your knowledge with your classmates either directly or via Piazza.

F# on Mac OS X

If you're using a Mac, you'll have to install a system that implements Microsoft's .NET architecture. The only system that I know of that does that is Mono. Mono is supported by Xamarin.

Xamarin

Xamarin gives away a free Eclipse-style cross-platform IDE called
Xamarin Studio. Xamarin Studio includes support for F#. (And we will soon be receiving some documentation support for some of the F# tools that we'll be using.)

Roll Your Own

If rigid IDEs aren't your cup of tea, you can do what I've done: download Mono for free and cobble together the set of F# tools that we'll use in CS3366 piece by piece. What follows is a summary of how I configured my Mac OS X 10.10 (Yosemite) system. In summary, you,ll need:

  1. The Mono implementation of .NET

  2. The F# Compiler (fsharpc) and the F# interpreter (fsharpi)

  3. Editor Support

  4. The fslex and fsyacc parser generation tools.
You'll also need several packages to support/help-install these items. If you get stuck trying to follow these instructions see either Ziyuan or Bob Muller.

Preliminaries

Fair Waring: Setting up an F# environment on OS X is a bit involved. To be clear, I set my environment up on OS X 10.10 Yosemite. I have no reason to believe that these instructions won't work on older versions of OS X. But I haven't tried all of them.

There are some preliminary steps that more-or-less restore OS X as a full Unix environment (rather than the clipped one that Apple ships as OS X).

  1. You're going to need Unix commands that don't ship with OS X.
    1. Visit Apple's App Store and install Xcode. You'll have to log in so you'll need to make an account if you don't already have one.
    2. Next, you'll have to download the Xcode's Command Line Tools from Apple's developer web site developer.apple.com. If you haven't done so already, you'll have to register for Apple's Developer program (it's free).

      Now visit Downloads for Apple Developers and download and install the appropriate version of Command Line Tools for Xcode.

  2. Apple stopped shipping support for Unix's X11 windowing system several releases ago. This is fine for the pure Mac world but lots of Unix applications require X11. Install the XQuartz implementation of X11 on your system.

  3. Install Macports. This is a handy package manager for OS X. It is invoked as the text command port from a Unix command shell (i.e., terminal window). Macports generally likes to put files in privileged folders (such as /opt/) so when you install a package using port, you'll generally want to be logged in on your computer as root. You can do this by using the Unix sudo command. Open a terminal window, then type:

    > sudo bash
    type your password
    # port install SOMETHING
    # exit
    >
    

  4. Use port to install automake and autoconf:

    > sudo bash
    type your password
    # port install automake
    ...
    # port install autoconf
    ...
    # exit
    >
    

Installing Mono, F# and Tools

  1. Visit the Mono Download site. Use the Download Mono MDK button to download Mono's Development Kit. Install it on your computer. When the installtion is done, check to confirm that it has been installed as an OS X-style Framework in /Library/Frameworks/.

  2. We're going to download the F# interpreter and compiler from Github. Visit https://github.com/fsharp/fsharp. You can use either the Clone in Desktop or Download ZIP buttons to download the sources for F#. As usual on Github, the installation instructions in README.md are found below by scrolling down.

    Using your Unix shell, cd into the installation folder fsharp that you downloaded onto your computer. The installation instructions for OS X indicate that you should run:

    ./autogen.sh --prefix=/Library/Frameworks/Mono.framework/Versions/Current/
    make
    sudo make install
    

    After you've done this, you should be able to type:

    > which fsharpi
    

    and Unix should indicate that the fsharpi command is found in /usr/bin/ (actually what is there is just a symlink pointing to a binary in your Frameworks area).

    Trying running fsharpi. Type an expression followed by 2 semicolons. Type #q;; to exit.

  3. Install F#'s lexer generator fslex and parser generator fsyacc. Note that these two tools were formerly part of the now defunct F# PowerPack. Visit FsLexYacc at Github. You can use either the Clone in Desktop or the Download ZIP buttons (on the right) as before. Follow the instructions in the README.md file to install it.

    We'll have some further instructions later about using fslex and fsyacc on your system.

    If you made it this far, pat yourself on the back!

Configuring your Editor

You can use your favorite text editor to edit your F# code. Both Emacs and Sublime Text (ST) are good options that come with special F# modes and which allow you to run an F# interpreter as a subprocess of the editor. I will flesh out the instructions for installing and configuring Sublime later. For now, we'll cover Emacs.

Installing and Setting up Emacs for Editting F# Code

In order to use Emacs to edit F# code, you'll need to be running Emacs version > 24. In the command shell, type:

      > emacs --version
If the version is older, use port to install the most recent release. Type:

      > sudo bash
      ...
      # port install emacs
      ...
      # exit
Confirm that you now have the correct version. (You may need to open a new terminal window.)

Now you can download the F# plug-in (aka a "binding") that makes Emacs understand F# syntax. There is a standard setup available on Github. But ZC has extended it to include handy key-bindings so we recommend that you use this one rather than the standard issue version. Download this archive and expand it in your home directory. The expanded form of the archive should be named dotemacsdotd/.

Emacs uses a special home-directory folder: .emacs.d/ for customization. If you're new to Emacs, you can simple rename your folder as follows:

> cd
> mv dotemacsdotd .emacs.d
> emacs test.fs

and you should see at the bottom that the ".fs" extension has caused Emacs to enter FSharp Mode. Type an F# definition or two. In Emacs, one is either typing text or control sequences, which seem quite strange to beginners. Control sequences usually involve the Control and/or the Escape keys. The former is usually denoted C or Ctrl, the latter is labeled esc and is usually denoted M or sometimes as Esc or as Meta. The notation C-c means "hold down the control key, then, while still holding it, type the 'c' key". And likewise for the meta key. For example, typing

C-h t

will fire up the Emacs tutorial. It's worth taking a look.

ZC has extended the keyboard short-cuts of F#'s emacs bindings to include:

C-c C-b

If you're running emacs in F# mode, C-c C-b should fire up an F# REPL (i.e., fsharpi) and send the contents of your editting buffer to the REPL for evaluation.

Emacs is a very powerful text editor and is well-worth mastering. Many of Emacs' commands have made their way into wider usage. For example, the emacs commands C-a, C-e, C-k and C-y will (resp) move the cursor to the front (i.e., left), to the end (i.e., right), "kill" (or delete) what's to the right or "yank" (or restore) what was most recently killed. These emacs commands (and many more) also work in other applications. For example, try positioning your cursor in the URL field of your browser and then see what happens when you type the various emacs commands.

The following Cheat Sheet should help.

Installing and Setting up Sublime Text for Editting F# Code

In abstract:
  1. Install Sublime Text

  2. Install Sublime Text's Package Manager

  3. Use Sublime Text's Package Manager to Install F# Syntax Mode.

  4. Use Sublime Text's Package Manager to Install F# REPL.
Created on 01-13-2015 13:14.