Saturday, October 16, 2010

Install F# on Mac OS X

This article is for Mono 2.8.x and older. Mono 2.10.x and newer contain F# out-of-the-box.
Since Mono 3.0.2, Our Mac can run F# 3.0. Please check F# 3.0 on Mac

F# is an object-oriented functional language by Microsoft. It's based on C#. I try to explain what technologies of Java-lang are corresponding to:
execution environmentobject-oriented languageobject-oriented functional language
Java technologiesJVMJavaScala
.NET technologiesCLRC#F#

And F# is also available on Mono, not only .NET . Let's install F# on Mac OS X from scratch!

  1. Download Mono 2.8 from here
  2. Install Mono 2.8
  3. Download mono.snk from here
  4. Download F# zip from here
  5. Unpack fsharp.zip
  6. cd /Library/Frameworks/Mono.framework/Versions/2.8/lib
  7. move unpacked directory (e.g. FSharp-2.0.0.0) to ./fsharp
  8. cd fsharp, and copy mono.snk to here
  9. sudo chown -R root:admin ../fsharp
  10. sudo ./install-mono.sh

At last, we had better aliasing two F# commands like below:
alias fsc='mono /Library/Frameworks/Mono.framework/Versions/2.8/lib/fsharp/bin/fsc.exe'
alias fsi='mono /Library/Frameworks/Mono.framework/Versions/2.8/lib/fsharp/bin/fsi.exe'

That's OK. Start the interactive shell:
$ fsi

Microsoft (R) F# 2.0 Interactive build 2.0.0.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> #light;;
> let Additional = (fun i j -> i + j);;

val Additional : int -> int -> int

> let sum = Additional 3 5;;

val sum : int = 8

> printf "%d" sum;;
8val it : unit = ()
> #quit;;

- Exit...
$

5 comments:

Fatu Huku said...

I followed all your steps, but when I ran fsi and tried to enter any commands at all, whether they be #light;; or expressions, the interpreter hangs indefinitely. Any idea why?

Youhei Kondou said...

No ideas. How about you doing a bug report for FSharp team?
http://fsxplat.codeplex.com/

Dmitry Klionsky said...

If it hands try:
alias fsi='mono /Library/Frameworks/Mono.framework/FSharp/bin/fsi.exe --gui- --readline+'

Unknown said...

Installing F# on Mac OSX is now really easy, a one step install - see http://fsharp.org

You use 'fsharpi' to run F# interactive

Youhei Kondou said...

OK, I see. It is insanely easy :-)

Post a Comment