strangelights.com

Main F# Site

Edit Edit
Print Print
Recent Changes Recent Changes
Subscriptions Subscriptions
Lost and Found Lost and Found
Find References Find References
Rename Rename
Search
List all versions List all versions
Raj
.
Summary

fsi.exe starts up a traditional command line interpreter for F#. Except it's not an interpreter - it generates real native code via JIT compilation to .NET IL. Here is the splash screen and a trivial execution:

  C:\fsharpv2>bin\fsi


  MSR F# Interactive, (c) Microsoft Corporation, All Rights Reserved
  F# Version 1.9.2.9, compiling for .NET Framework Version v2.0.50727


  NOTE:
  NOTE: See 'fsi --help' for flags
  NOTE:
  NOTE: Commands: #r <string>;;    reference (dynamically load) the given DLL.
  NOTE:           #I <string>;;    add the given search path for referenced DLLs.


  NOTE:           #use <string>;;  accept input from the given file.
  NOTE:           #load <string> ...<string>;;
  NOTE:                            load the given file(s) as a compilation unit.
  NOTE:           #time;;          toggle timing on/off.
  NOTE:           #types;;         toggle display of types on/off.
  NOTE:           #quit;;          exit.
  NOTE:
  NOTE: Visit the F# website at http://research.microsoft.com/fsharp.
  NOTE: Bug reports to fsbugs@microsoft.com. Enjoy!  


  > let rec f x = (if x < 2 then x else f (x-1) + f (x-2));;


  val f : int -> int


  > f 6;;


  val it = 8


  val it : int

You can exit fsi via: '#quit;;' OR '#q;;' OR 'exit 0;;' .

You can load, then open files thus: #load "my_file.fs";; open My_file''. Note that a file without defined modules has an implicit module name. The implicit module is named by capitalizing the filename and dropping the extension. After loading a file, you will need to open it, to use its contents.

Alternatively, you can load when invoking fsi: c:\> fsi my_file.fs . Then, when fsi is running: 'open My_file;;'.

You can dynamically load new DLLs (.NET libraries) into fsi using #r. For example, you can use the following to load up ManagedDirectX (path depends on which version of DirectX you've got)

  #I @"C:\WINDOWS\Microsoft.NET\Managed DirectX\v9.05.132" ;;
  #r @"Microsoft.DirectX.dll";;
  #r @"Microsoft.DirectX.Direct3D.dll" ;;
  #r @"Microsoft.DirectX.Direct3Dx.dll" ;;

Some things are a bit quirky with FSI. Like the OCaml top level you need to enter ";;" a lot. You also need to add a ";;" immediately after all "open" declarations:

  open Microsoft.DirectX
  open Microsoft.DirectX.Direct3D
  open System.Drawing;;

You can even enter classes directly. For example

  type StartStop(x:int) = 
    class 
      let y = x + 1
      member obj.XY = (x,y)
    end
Welcome to F Sharp Wiki, view the HomePage

This site supports the new NoFollow anti-spam initiative.

Recent Topics

Copyright 2005, Robert Pickering (Others where credited) | Terms of Use