HaskellWiki

Haskell | Wiki community | Recent changes
Random page | Special pages

 

Not logged in
Log in | Help

Note: new account creation has been disabled as an anti-spam measure.

Salsa

Categories: Tools | Libraries


Contents

1 About

Salsa is an experimental Haskell library and code generator that allows Haskell programs to host the .NET runtime and interact with .NET libraries. It uses type families extensively to provide a type-safe mapping of the .NET object model in the Haskell type system.

2 Requirements

GHC 6.8
Salsa makes extensive use of type families and thus requires at least version 6.8 of GHC.
Microsoft .NET Framework 3.5
Since the Salsa code generator requires .NET 3.5, any Salsa development also requires this version. Executables produced with Salsa however will run with just .NET 2.0 (provided that only .NET 2.0 assemblies are used by the program).
Salsa will not work with versions 1.0/1.1 of the .NET Framework, or with Mono. (Supporting Mono shouldn't be too much work though.)
Caution!
Salsa is experimental and has not been thoroughly tested. A single typographical error can trigger multiple pages of errors from GHC, or cause it to eat lots of memory.

3 Getting Salsa

You can find Salsa on Hackage. There is also a darcs repository:

darcs get http://code.haskell.org/Salsa

(you’ll need Darcs 2).

4 Using Salsa

Having a look at the sample programs in the Salsa distribution is probably the best way to learn how to use Salsa at the moment. There are currently three sample programs available:

4.1 C# in Haskell

The following table shows some C# code snippets and what they translate to:

C# Salsa Notes
o.ToString()
o # _toString () Method names have a leading underscore and lowercase first character.
Console.Write("Hi {0}!", "world");
_Console # _write ("Hi {0}!", "world") Static methods are called similarly.
Button b = new Button();
b <- new _Button () Constructor names have a leading underscore.
s.Length
get s _Length Use the get function to retrieve field and property values. The field/property has a leading underscore.
b.Text = "OK";
set b [_Text := "OK"] Use the set function to set the value of fields and properties. Multiple assignments can be made in the one call.
b.Width = 10;
set b [_Width :== 10 ] Use :== to assign without applying implicit conversions. This is useful for assigning polymorphic numeric literals to properties, since polymorphic-typed values confuse the Salsa coercion machinery.
b.Click += (EventHandler)
  delegate(...) { ... };
set b [_Click :+> delegate _EventHandler (...)] Use :+> to add a handler to an event, and delegate to wrap a Haskell function as a .NET delegate.

5 Limitations

There are a number of .NET features that Salsa does not currently support. These include:

Also, only a handful of value types are automatically marshaled between Haskell and .NET (these are Int32, String, Bool and Double). All other types are marshaled by reference (which is typically what you want for .NET reference types anyway).

(Patches are certainly welcome.)

6 Documentation

Some of the inner workings of Salsa are described in my undergraduate thesis. In particular, Chapter 8 describes how type families are used to provide a type-safe mapping of the .NET object model in Haskell. If you're considering playing with Salsa, it is probably worth a read:

A .NET Bridge for Haskell: Dancing with the Devil

Retrieved from "http://haskell.org/haskellwiki/Salsa"

This page has been accessed 3,059 times. This page was last modified 13:34, 10 October 2008. Recent content is available under a simple permissive license.