https://wiki.haskell.org/api.php?action=feedcontributions&user=AndrewAppleyard&feedformat=atomHaskellWiki - User contributions [en]2024-03-28T20:34:49ZUser contributionsMediaWiki 1.35.5https://wiki.haskell.org/index.php?title=Salsa&diff=55313Salsa2013-01-27T08:47:09Z<p>AndrewAppleyard: </p>
<hr />
<div>[[Category:Tools]]<br />
[[Category:Libraries]]<br />
<br />
== About ==<br />
<br />
Salsa is an ''experimental'' Haskell library and code generator that allows<br />
Haskell programs to host the .NET runtime and interact with .NET libraries.<br />
It uses type families extensively to provide a type-safe mapping of the .NET<br />
object model in the Haskell type system.<br />
<br />
== Requirements ==<br />
<br />
; '''GHC 6.8'''<br />
<br />
: Salsa makes extensive use of type families and thus requires at least version 6.8 of GHC. Current versions of GHC have not been tested.<br />
<br />
; '''Microsoft .NET Framework 3.5'''<br />
<br />
: 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).<br />
<br />
: 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.)<br />
<br />
; '''Caution!'''<br />
<br />
: 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.<br />
<br />
== Getting Salsa ==<br />
<br />
You can find Salsa on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Salsa Hackage]. There is also a repository on [https://github.com/unfoldr/Salsa GitHub]:<br />
<br />
<blockquote><br />
<tt>git clone git://github.com/unfoldr/Salsa.git</tt><br />
</blockquote><br />
<br />
== Using Salsa ==<br />
<br />
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:<br />
<br />
* [http://code.haskell.org/Salsa/Samples/Hello Hello]: a basic console 'Hello World' program.<br />
<br />
* [http://code.haskell.org/Salsa/Samples/Weather Weather]: a console program that asynchronously downloads the Sydney weather forecast and displays it.<br />
<br />
* [http://code.haskell.org/Salsa/Samples/Conway Conway]: a simulator for Conway's Game of Life with a Windows Presentation Foundation GUI. (Requires .NET 3.0 or later.)<br />
<br />
=== C# in Haskell ===<br />
<br />
The following table shows some C# code snippets and what they translate to:<br />
<br />
{| <br />
!width="35%"| C# <br />
!width="35%"| Salsa <br />
!width="30%"| Notes<br />
|-<br />
| <pre-c>o.ToString()</pre-c> <br />
| <hask>o # _toString ()</hask><br />
| <small>Method names have a leading underscore and lowercase first character.</small><br />
|-<br />
| <pre-c>Console.Write("Hi {0}!", "world");</pre-c> <br />
| <hask>_Console # _write ("Hi {0}!", "world")</hask><br />
| <small>Static methods are called similarly.</small><br />
|-<br />
| <pre-c>Button b = new Button();</pre-c><br />
| <hask>b <- new _Button ()</hask><br />
| <small>Constructor names have a leading underscore.</small><br />
|-<br />
| <pre-c>s.Length</pre-c><br />
| <hask>get s _Length</hask><br />
| <small>Use the <hask>get</hask> function to retrieve field and property values. The field/property has a leading underscore.</small><br />
|-<br />
| <pre-c>b.Text = "OK";</pre-c><br />
| <hask>set b [_Text := "OK"]</hask><br />
| <small>Use the <hask>set</hask> function to set the value of fields and properties. Multiple assignments can be made in the one call.</small><br />
|-<br />
| <pre-c>b.Width = 10;</pre-c><br />
| <hask>set b [_Width :== 10 ]</hask><br />
| <small>Use <hask>:==</hask> 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.</small><br />
|-<br />
| <pre-c>b.Click += (EventHandler)<br />
delegate(...) { ... };</pre-c><br />
| <hask>set b [_Click :+> delegate _EventHandler (...)]</hask><br />
| <small>Use <hask>:+></hask> to add a handler to an event, and <hask>delegate</hask> to wrap a Haskell function as a .NET delegate.</small><br />
|}<br />
<br />
== Limitations ==<br />
<br />
There are a number of .NET features that Salsa does not currently support. These include:<br />
<br />
* generic methods and classes<br />
* multi-dimensional arrays<br />
* explicit coercions<br />
* indexer properties<br />
* exception handling<br />
<br />
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).<br />
<br />
(Patches are certainly welcome.)<br />
<br />
== Documentation ==<br />
<br />
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:<br />
<br />
<blockquote><br />
[http://code.haskell.org/Salsa/Docs/Thesis.pdf A .NET Bridge for Haskell: Dancing with the Devil]<br />
</blockquote></div>AndrewAppleyardhttps://wiki.haskell.org/index.php?title=Applications_and_libraries/Interfacing_other_languages&diff=23407Applications and libraries/Interfacing other languages2008-10-10T12:19:41Z<p>AndrewAppleyard: Added Salsa</p>
<hr />
<div>{{unknown copyright}}<br />
{{LibrariesPage}}<br />
<br />
== Tools for interfacing with other languages ==<br />
<br />
Haskell builtin features for interfacing to other languages are formally defined in the<br />
[http://www.cse.unsw.edu.au/~chak/haskell/ffi/ Foreign Function Interface (FFI)]. You may learn it by example at the <br />
[http://haskell.org/haskellwiki/IO_inside#Interfacing_with_C.2FC.2B.2B_and_foreign_libraries_.28under_development.29 IO inside] guide.<br />
<br />
See also [[RPC | Web services and RPC]].<br />
<br />
The following tools and libraries either simplify interfacing to C or allow interfacing to other languages and environments (COM, JVM, Python, Tcl, Lua...).<br />
<br />
=== C ===<br />
<br />
;[http://www.cse.unsw.edu.au/~chak/haskell/c2hs/ C-&gt;Haskell]<br />
:A lightweight tool for implementing access to C libraries from Haskell.<br />
<br />
;[http://hsffig.sourceforge.net HSFFIG]<br />
:Haskell FFI Binding Modules Generator (HSFFIG) is a tool that takes a C library include file (.h) and generates Haskell Foreign Functions Interface import declarations for items (functions, structures, etc.) the header defines.<br />
<br />
;[http://www.astercity.net/~khaliff/haskell/kdirect/index.html KDirect]<br />
:A tool to simplify the process of interfacing C libraries to Haskell. It is less powerful than HaskellDirect, but easier to use and more portable.<br />
<br />
=== Java ===<br />
<br />
;[http://www.haskell.org/gcjni GCJNI]<br />
:A Java Native Interface for Haskell. Allows Haskell to invoke Java code. Includes a tool to generate Haskell bindings for a Java library. Works for hugs and ghc under both Linux and Windows. (Based on Greencard, see above.)<br />
<br />
;[http://sourceforge.net/projects/jvm-bridge/ Haskell/Java VM Bridge]<br />
:A bridge to the Java virtual machine via JNI for Haskell.<br />
<br />
;[http://labs.businessobjects.com/cal/ CAL]<br />
:A hybrid language of Java and Haskell.<br />
<br />
=== Python ===<br />
<br />
;[http://quux.org/devel/missingpy MissingPy]<br />
:MissingPy is really two libraries in one. At its lowest level, MissingPy is a library designed to make it easy to call into Python from Haskell. It provides full support for interpreting arbitrary Python code, interfacing with a good part of the Python/C API, and handling Python objects. It also provides tools for converting between Python objects and their Haskell equivalents. Memory management is handled for you, and Python exceptions get mapped to Haskell Dynamic exceptions. At a higher level, MissingPy contains Haskell interfaces to some Python modules.<br />
<br />
=== Others ===<br />
<br />
;[http://web.archive.org/web/20010306205042/http://www.numeric-quest.com/haskell/smartest.html Smarty]<br />
:An interface between Haskell and Squeak, a freely available Smalltalk language and environment.<br />
<br />
;[ftp://ftp.cs.york.ac.uk/pub/haskell/contrib/lp2fp.tar.gz]<br />
:lp2fp is a program-translator from Prolog to Haskell.<br />
<br />
;[http://haskell.org/haskellscript/ HaskellScript]<br />
:HaskellScript is the collective name for all Haskell components, both tools and libararies, that allow interaction with the COM/ActiveX framework.<br />
<br />
;[http://www.cse.unsw.edu.au/~dons/haskell-1990-2000/msg04613.html TclHaskell]<br />
:TclHaskell is a haskell binding to Tcl-Tk that lets you build GUIs in Haskell. It is Haskell98 compliant. It has been tested under hugs98 and ghc-4.04.<br />
<br />
;[[CPlusPlusFromHaskell]]<br />
:A hackish method calling C++ from Haskell.<br />
<br />
;[[HsLua]]<br />
:Haskell interface to Lua scripting language (tested with GHC 6.6/6.8).<br />
<br />
;[[Salsa]]<br />
:An experimental .NET Bridge for Haskell.<br />
<br />
=== Obsolete ===<br />
<br />
;[http://www.reid-consulting-uk.ltd.uk/docs/ffi.html Guide to Haskell's Foreign Function Interface] <br />
:Comparision of the different tools.<br />
<br />
;[http://haskell.org/greencard/ Green Card]</dt><br />
: Green Card is a foreign function interface preprocessor for Haskell, simplifying the task of interfacing Haskell programs to external libraries (which are normally exposed via C interfaces). Green Card is currently able to generate code compatible with [[Implementations#The_Haskell_Interpreter_Hugs| Hugs]] and [[Implementations#nhc98 | nhc]]. Green Card is compatible with the [[Implementations#GHC_the_Glasgow_Haskell_Compiler | Glasgow Haskell Compiler]] (GHC), versions prior to 6.2. <br />
:Green Card is not compatible with GHC versions 6.2 and later because Green Card uses a deprecated form of Foreign Function Interface (FFI) binding, _casm_: such old-style bindings were removed in GHC version 6.2. See [http://www.mail-archive.com/haskell@haskell.org/msg14004.html ANNOUNCE: GHC version 6.2].<br />
<br />
;[http://haskell.org/hdirect/ HaskellDirect]<br />
:HaskellDirect is an Interface Definition Language (IDL) compiler for Haskell, which helps interfacing Haskell code to libraries or components written in other languages (C). An IDL specification specifies the type signatures and types expected by a set of external functions. One important use of this language neutral specification of interfaces is to specify COM (Microsoft's Component Object Model) interfaces, and HaskellDirect offers special support for both using COM objects from Haskell and creating Haskell COM objects. HaskellDirect groks both the OSF DCE dialect of IDL (including the various extensions introduced by the Microsoft IDL compiler) and the OMG IIOP/CORBA dialect. '''Not compatible with recent versions of GHC (6.6.1)'''<br />
<br />
;[http://www.haskell.org/hdirect/ Lambada]<br />
:A Haskell <=> Java interoperation bridge. Interoperation between Haskell and Java is provided by Lambada via the Java Native Interface (JNI), giving you a set of Haskell abstractions that lets you both call out to Java from Haskell *and* wrap up Haskell code behind a Java-callable veneer. '''Not compatible with recent versions of GHC (6.6.1)'''</div>AndrewAppleyardhttps://wiki.haskell.org/index.php?title=Salsa&diff=23406Salsa2008-10-10T11:47:41Z<p>AndrewAppleyard: Added references to the Salsa sample programs</p>
<hr />
<div>[[Category:Tools]]<br />
[[Category:Libraries]]<br />
<br />
== About ==<br />
<br />
Salsa is an experimental Haskell library and code generator that allows<br />
Haskell programs to host the .NET runtime and interact with .NET libraries.<br />
It uses type families extensively to provide a type-safe mapping of the .NET<br />
object model in the Haskell type system.<br />
<br />
== Requirements ==<br />
<br />
; '''GHC 6.8'''<br />
<br />
: Salsa makes extensive use of type families and thus requires at least version 6.8 of GHC.<br />
<br />
; '''Microsoft .NET Framework 3.5'''<br />
<br />
: 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).<br />
<br />
: 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.)<br />
<br />
; '''Caution!'''<br />
<br />
: 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.<br />
<br />
== Getting Salsa ==<br />
<br />
You can find Salsa on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Salsa Hackage]. There is also a darcs repository:<br />
<br />
<blockquote><br />
<tt>darcs get http://code.haskell.org/Salsa</tt><br />
</blockquote><br />
<br />
(you’ll need Darcs 2).<br />
<br />
== Using Salsa ==<br />
<br />
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:<br />
<br />
* [http://code.haskell.org/Salsa/Samples/Hello Hello]: a basic console 'Hello World' program.<br />
<br />
* [http://code.haskell.org/Salsa/Samples/Weather Weather]: a console program that asynchronously downloads the Sydney weather forecast and displays it.<br />
<br />
* [http://code.haskell.org/Salsa/Samples/Conway Conway]: a simulator for Conway's Game of Life with a Windows Presentation Foundation GUI. (Requires .NET 3.0 or later.)<br />
<br />
=== C# in Haskell ===<br />
<br />
The following table shows some C# code snippets and what they translate to:<br />
<br />
{| <br />
!width="35%"| C# <br />
!width="35%"| Salsa <br />
!width="30%"| Notes<br />
|-<br />
| <pre-c>o.ToString()</pre-c> <br />
| <hask>o # _toString ()</hask><br />
| <small>Method names have a leading underscore and lowercase first character.</small><br />
|-<br />
| <pre-c>Console.Write("Hi {0}!", "world");</pre-c> <br />
| <hask>_Console # _write ("Hi {0}!", "world")</hask><br />
| <small>Static methods are called similarly.</small><br />
|-<br />
| <pre-c>Button b = new Button();</pre-c><br />
| <hask>b <- new _Button ()</hask><br />
| <small>Constructor names have a leading underscore.</small><br />
|-<br />
| <pre-c>s.Length</pre-c><br />
| <hask>get s _Length</hask><br />
| <small>Use the <hask>get</hask> function to retrieve field and property values. The field/property has a leading underscore.</small><br />
|-<br />
| <pre-c>b.Text = "OK";</pre-c><br />
| <hask>set b [_Text := "OK"]</hask><br />
| <small>Use the <hask>set</hask> function to set the value of fields and properties. Multiple assignments can be made in the one call.</small><br />
|-<br />
| <pre-c>b.Width = 10;</pre-c><br />
| <hask>set b [_Text :== 10 ]</hask><br />
| <small>Use <hask>:==</hask> 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.</small><br />
|-<br />
| <pre-c>b.Click += (EventHandler)<br />
delegate(...) { ... };</pre-c><br />
| <hask>set b [_Click :+> delegate _EventHandler (...)]</hask><br />
| <small>Use <hask>:+></hask> to add a handler to an event, and <hask>delegate</hask> to wrap a Haskell function as a .NET delegate.</small><br />
|}<br />
<br />
== Limitations ==<br />
<br />
There are a number of .NET features that Salsa does not currently support. These include:<br />
<br />
* generic methods and classes<br />
* multi-dimensional arrays<br />
* explicit coercions<br />
* indexer properties<br />
* exception handling<br />
<br />
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).<br />
<br />
(Patches are certainly welcome.)<br />
<br />
== Documentation ==<br />
<br />
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:<br />
<br />
<blockquote><br />
[http://code.haskell.org/Salsa/Docs/Thesis.pdf A .NET Bridge for Haskell: Dancing with the Devil]<br />
</blockquote></div>AndrewAppleyardhttps://wiki.haskell.org/index.php?title=Salsa&diff=23405Salsa2008-10-10T07:11:11Z<p>AndrewAppleyard: Removed TODO</p>
<hr />
<div>[[Category:Tools]]<br />
[[Category:Libraries]]<br />
<br />
== About ==<br />
<br />
Salsa is an experimental Haskell library and code generator that allows<br />
Haskell programs to host the .NET runtime and interact with .NET libraries.<br />
It uses type families extensively to provide a type-safe mapping of the .NET<br />
object model in the Haskell type system.<br />
<br />
== Requirements ==<br />
<br />
; '''GHC 6.8'''<br />
<br />
: Salsa makes extensive use of type families and thus requires at least version 6.8 of GHC.<br />
<br />
; '''Microsoft .NET Framework 3.5'''<br />
<br />
: 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).<br />
<br />
: 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.)<br />
<br />
; '''Caution!'''<br />
<br />
: 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.<br />
<br />
== Getting Salsa ==<br />
<br />
You can find Salsa on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Salsa Hackage]. There is also a darcs repository:<br />
<br />
<blockquote><br />
<tt>darcs get http://code.haskell.org/Salsa</tt><br />
</blockquote><br />
<br />
(you’ll need Darcs 2).<br />
<br />
== Using Salsa ==<br />
<br />
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.<br />
<br />
The following table shows some C# code snippets and what they translate to:<br />
<br />
{| <br />
!width="35%"| C# <br />
!width="35%"| Salsa <br />
!width="30%"| Notes<br />
|-<br />
| <pre-c>o.ToString()</pre-c> <br />
| <hask>o # _toString ()</hask><br />
| <small>Method names have a leading underscore and lowercase first character.</small><br />
|-<br />
| <pre-c>Console.Write("Hi {0}!", "world");</pre-c> <br />
| <hask>_Console # _write ("Hi {0}!", "world")</hask><br />
| <small>Static methods are called similarly.</small><br />
|-<br />
| <pre-c>Button b = new Button();</pre-c><br />
| <hask>b <- new _Button ()</hask><br />
| <small>Constructor names have a leading underscore.</small><br />
|-<br />
| <pre-c>s.Length</pre-c><br />
| <hask>get s _Length</hask><br />
| <small>Use the <hask>get</hask> function to retrieve field and property values. The field/property has a leading underscore.</small><br />
|-<br />
| <pre-c>b.Text = "OK";</pre-c><br />
| <hask>set b [_Text := "OK"]</hask><br />
| <small>Use the <hask>set</hask> function to set the value of fields and properties. Multiple assignments can be made in the one call.</small><br />
|-<br />
| <pre-c>b.Width = 10;</pre-c><br />
| <hask>set b [_Text :== 10 ]</hask><br />
| <small>Use <hask>:==</hask> 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.</small><br />
|-<br />
| <pre-c>b.Click += (EventHandler)<br />
delegate(...) { ... };</pre-c><br />
| <hask>set b [_Click :+> delegate _EventHandler (...)]</hask><br />
| <small>Use <hask>:+></hask> to add a handler to an event, and <hask>delegate</hask> to wrap a Haskell function as a .NET delegate.</small><br />
|}<br />
<br />
== Limitations ==<br />
<br />
There are a number of .NET features that Salsa does not currently support. These include:<br />
<br />
* generic methods and classes<br />
* multi-dimensional arrays<br />
* explicit coercions<br />
* indexer properties<br />
* exception handling<br />
<br />
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).<br />
<br />
(Patches are very welcome.)<br />
<br />
== Documentation ==<br />
<br />
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:<br />
<br />
<blockquote><br />
[http://code.haskell.org/Salsa/Docs/Thesis.pdf A .NET Bridge for Haskell: Dancing with the Devil]<br />
</blockquote></div>AndrewAppleyardhttps://wiki.haskell.org/index.php?title=Salsa&diff=23403Salsa2008-10-10T06:36:57Z<p>AndrewAppleyard: Moved limitations section.</p>
<hr />
<div>[[Category:Tools]]<br />
[[Category:Libraries]]<br />
<br />
== About ==<br />
<br />
Salsa is an experimental Haskell library and code generator that allows<br />
Haskell programs to host the .NET runtime and interact with .NET libraries.<br />
It uses type families extensively to provide a type-safe mapping of the .NET<br />
object model in the Haskell type system.<br />
<br />
== Requirements ==<br />
<br />
; '''GHC 6.8'''<br />
<br />
: Salsa makes extensive use of type families and thus requires at least version 6.8 of GHC.<br />
<br />
; '''Microsoft .NET Framework 3.5'''<br />
<br />
: 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).<br />
<br />
: 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.)<br />
<br />
; '''Caution!'''<br />
<br />
: 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.<br />
<br />
== Getting Salsa ==<br />
<br />
('''TODO''') You can find Salsa on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Salsa Hackage]. There is also a darcs repository:<br />
<br />
<blockquote><br />
<tt>darcs get http://code.haskell.org/Salsa</tt><br />
</blockquote><br />
<br />
(you’ll need Darcs 2).<br />
<br />
== Using Salsa ==<br />
<br />
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.<br />
<br />
The following table shows some C# code snippets and what they translate to:<br />
<br />
{| <br />
!width="35%"| C# <br />
!width="35%"| Salsa <br />
!width="30%"| Notes<br />
|-<br />
| <pre-c>o.ToString()</pre-c> <br />
| <hask>o # _toString ()</hask><br />
| <small>Method names have a leading underscore and lowercase first character.</small><br />
|-<br />
| <pre-c>Console.Write("Hi {0}!", "world");</pre-c> <br />
| <hask>_Console # _write ("Hi {0}!", "world")</hask><br />
| <small>Static methods are called similarly.</small><br />
|-<br />
| <pre-c>Button b = new Button();</pre-c><br />
| <hask>b <- new _Button ()</hask><br />
| <small>Constructor names have a leading underscore.</small><br />
|-<br />
| <pre-c>s.Length</pre-c><br />
| <hask>get s _Length</hask><br />
| <small>Use the <hask>get</hask> function to retrieve field and property values. The field/property has a leading underscore.</small><br />
|-<br />
| <pre-c>b.Text = "OK";</pre-c><br />
| <hask>set b [_Text := "OK"]</hask><br />
| <small>Use the <hask>set</hask> function to set the value of fields and properties. Multiple assignments can be made in the one call.</small><br />
|-<br />
| <pre-c>b.Width = 10;</pre-c><br />
| <hask>set b [_Text :== 10 ]</hask><br />
| <small>Use <hask>:==</hask> 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.</small><br />
|-<br />
| <pre-c>b.Click += (EventHandler)<br />
delegate(...) { ... };</pre-c><br />
| <hask>set b [_Click :+> delegate _EventHandler (...)]</hask><br />
| <small>Use <hask>:+></hask> to add a handler to an event, and <hask>delegate</hask> to wrap a Haskell function as a .NET delegate.</small><br />
|}<br />
<br />
== Limitations ==<br />
<br />
There are a number of .NET features that Salsa does not currently support. These include:<br />
<br />
* generic methods and classes<br />
* multi-dimensional arrays<br />
* explicit coercions<br />
* indexer properties<br />
* exception handling<br />
<br />
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).<br />
<br />
(Patches are very welcome.)<br />
<br />
== Documentation ==<br />
<br />
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:<br />
<br />
[http://code.haskell.org/Salsa/Docs/Thesis.pdf A .NET Bridge for Haskell: Dancing with the Devil]</div>AndrewAppleyardhttps://wiki.haskell.org/index.php?title=Salsa&diff=23402Salsa2008-10-10T06:35:57Z<p>AndrewAppleyard: Initial edit</p>
<hr />
<div>[[Category:Tools]]<br />
[[Category:Libraries]]<br />
<br />
== About ==<br />
<br />
Salsa is an experimental Haskell library and code generator that allows<br />
Haskell programs to host the .NET runtime and interact with .NET libraries.<br />
It uses type families extensively to provide a type-safe mapping of the .NET<br />
object model in the Haskell type system.<br />
<br />
== Requirements ==<br />
<br />
; '''GHC 6.8'''<br />
<br />
: Salsa makes extensive use of type families and thus requires at least version 6.8 of GHC.<br />
<br />
; '''Microsoft .NET Framework 3.5'''<br />
<br />
: 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).<br />
<br />
: 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.)<br />
<br />
; '''Caution!'''<br />
<br />
: 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.<br />
<br />
== Limitations ==<br />
<br />
There are a number of .NET features that Salsa does not currently support. These include:<br />
<br />
* generic methods and classes<br />
* multi-dimensional arrays<br />
* explicit coercions<br />
* indexer properties<br />
* exception handling<br />
<br />
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).<br />
<br />
(Patches are very welcome.)<br />
<br />
== Getting Salsa ==<br />
<br />
('''TODO''') You can find Salsa on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Salsa Hackage]. There is also a darcs repository:<br />
<br />
<blockquote><br />
<tt>darcs get http://code.haskell.org/Salsa</tt><br />
</blockquote><br />
<br />
(you’ll need Darcs 2).<br />
<br />
== Using Salsa ==<br />
<br />
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.<br />
<br />
The following table shows some C# code snippets and what they translate to:<br />
<br />
{| <br />
!width="35%"| C# <br />
!width="35%"| Salsa <br />
!width="30%"| Notes<br />
|-<br />
| <pre-c>o.ToString()</pre-c> <br />
| <hask>o # _toString ()</hask><br />
| <small>Method names have a leading underscore and lowercase first character.</small><br />
|-<br />
| <pre-c>Console.Write("Hi {0}!", "world");</pre-c> <br />
| <hask>_Console # _write ("Hi {0}!", "world")</hask><br />
| <small>Static methods are called similarly.</small><br />
|-<br />
| <pre-c>Button b = new Button();</pre-c><br />
| <hask>b <- new _Button ()</hask><br />
| <small>Constructor names have a leading underscore.</small><br />
|-<br />
| <pre-c>s.Length</pre-c><br />
| <hask>get s _Length</hask><br />
| <small>Use the <hask>get</hask> function to retrieve field and property values. The field/property has a leading underscore.</small><br />
|-<br />
| <pre-c>b.Text = "OK";</pre-c><br />
| <hask>set b [_Text := "OK"]</hask><br />
| <small>Use the <hask>set</hask> function to set the value of fields and properties. Multiple assignments can be made in the one call.</small><br />
|-<br />
| <pre-c>b.Width = 10;</pre-c><br />
| <hask>set b [_Text :== 10 ]</hask><br />
| <small>Use <hask>:==</hask> 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.</small><br />
|-<br />
| <pre-c>b.Click += (EventHandler)<br />
delegate(...) { ... };</pre-c><br />
| <hask>set b [_Click :+> delegate _EventHandler (...)]</hask><br />
| <small>Use <hask>:+></hask> to add a handler to an event, and <hask>delegate</hask> to wrap a Haskell function as a .NET delegate.</small><br />
|}<br />
<br />
== Documentation ==<br />
<br />
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:<br />
<br />
[http://code.haskell.org/Salsa/Docs/Thesis.pdf A .NET Bridge for Haskell: Dancing with the Devil]</div>AndrewAppleyardhttps://wiki.haskell.org/index.php?title=User:AndrewAppleyard&diff=23401User:AndrewAppleyard2008-10-10T05:14:36Z<p>AndrewAppleyard: </p>
<hr />
<div>[[Salsa]]</div>AndrewAppleyard