1 / 22

Building .NET GUIs for Haskell applications

Building .NET GUIs for Haskell applications. Beatriz Alarcón Jiménez balarcon@dsic.upv.es. Outline. Introduction Overview of .NET graphic controls A simple case study Interoperability by means of COM in Haskell Integration of COM into .NET A .NET version of Mu-term

cara
Download Presentation

Building .NET GUIs for Haskell applications

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Building .NET GUIs for Haskell applications Beatriz Alarcón Jiménez balarcon@dsic.upv.es

  2. Outline • Introduction • Overview of .NET graphic controls • A simple case study • Interoperability by means of COM in Haskell • Integration of COM into .NET • A .NET version of Mu-term • Conclusions and future work .NET Technologies 2006

  3. Introduction • .NET: a new framework for Software Development • Functional languages: Haskell • Advantages: powerful features for developing software • Disadvantages: lack of an Integrated Development Environment (IDE) to build GUIs • COM (Component Object Model) .NET Technologies 2006

  4. Introduction • From Haskell to .NET through COM • Starting point: Haskell Direct A framework for Haskell FFI (Foreign Fuction Interface) based on the standard IDL (Interface Definition Language) DLL COM COM component Haskell component .NET Technologies 2006

  5. Overview of .NET graphic controls • System.Windows.Forms namespace • .NET controls and data .NET Technologies 2006

  6. A simple case study • Simple graphic interface to introduce and manipulate strings by means of simple transformations: • Converting the characters of the string into capital or small letters • Removing spare blank spaces • Simple encryption (Caesar’s method) .NET Technologies 2006

  7. A simple case study • In the Haskell part (Hlist.hs): type Focus = Int type Length = Int data HL = H_L [(String, Length)] Focus deriving Show addPair :: HL -> String -> HL -- Adds a new string and its length getString :: HL -> String -- Obtains the `current' string writeString :: HL -> String -> HL -- Updates the `current' string getLength :: HL -> Int -- Length of the `current' string setFocus :: HL -> Int -> HL -- Sets the (index of) `current' string toUpperCase :: String -> String toLowerCase :: String -> String deleteB :: String -> String encrypt :: String -> String .NET Technologies 2006

  8. Interoperability by means of COM in Haskell • A Haskell program that implements a COM component consists of four parts: • The application code, written in Haskell by the programmer • An IDL specification describing the Haskell functions which we want to make accesible through the COM interface • A set of Haskell modules which are automatically generated from the IDL by the HDirect tool • A Haskell library module, Com, that exports all the functions needed to support COM objects in Haskell and a C library module that provides some Run-Time Support (RTS) .NET Technologies 2006

  9. Example.idl HDirect ExampleProxy.hs EXAMPLE.hs Com.lhs (library) RTS A Haskell COM component Hlist.hs .NET Technologies 2006

  10. The IDL of the Haskell Component • IDL is a declarative language to describe the interface of a component • In the IDL specification we declare (the profiles of the Haskell) functions we wish to have accesible from C# code • The interface for the function deleteB extracted from example.idl: HRESULT deleteB(); .NET Technologies 2006

  11. Encapsulating a Haskell component as a COM component • Once the IDL has been specified, the next step is to generate the proxy (ExampleProxy.hs, automatically) and the skeleton of the component • Regarding the definition of the skeleton, HDirect accomplishes the following tasks: • To import the necessary Haskell modules • To introduce a State type to implement the persistence of the funtional data by means of a mutable variable • To include Haskell declarations corresponding to the funtions defined in the IDL .NET Technologies 2006

  12. Encapsulating a Haskell component as a COM component module EXAMPLE where (...) import IOExts import qualified Hlist --Pure Haskell Component data State = State(IORef HList.HL) deleteB :: State -> Prelude.IO () deleteB (State st) = do { hl <- readIORef st ; str' <- Prelude.return (HList.deleteB (HList.getString hl)) ; writeIORef st (HList.writeString str' hl) } (…) .NET Technologies 2006

  13. Creating a COM DLL from Haskell modules • After compiling these modules, it is necessary to provide a Main module. • Once the module Main has been compiled, we use HDirect to build the type library (.tlb) from the IDL and the proxy (example.tlb) • We must bind the type library to our DLL • Now, we can build the DLL including all compiled modules of the application .NET Technologies 2006

  14. Integration of COM into .NET • Register the DLL (regsvr32.exe) • The data types, error management,…are different for managed and unmanaged objects • Tlbimp is a console application that converts the type definitions in a COM type library into equivalent .NET assembly definitions • Now, in VS .NET, we can add the generated assembly as reference in our Windows application .NET Technologies 2006

  15. Integration of COM into .NET • In the C# component, we create an instance of the class • ExampleClass h=new ExampleClass(); • Haskell functions can be accessed as if they were C# functions .NET Technologies 2006

  16. Example.cs private void update() { this.index=this.cbTextList.SelectedIndex; string str=h.getString(); this.tbEntryText.Text=str; this.tbLength.Text=h.getLength().ToString(); this.cbTextList.Items.RemoveAt(index); this.cbTextList.Items.Insert(index,str); this.cbTextList.Text=str; } private void bdeleteBln_Click(object sender, System.EventArgs e) { h.deleteB(); this.update(); } .NET Technologies 2006

  17. A .NET version of Mu-term • Mu-term is a termination proof tool for (Context-Sensitive) Rewriting Systems • Mu-term is written in Haskell and wxHaskell was used to develop the graphical user interface • The system consists of around 30 Haskell modules containing more than 5000 lines of code .NET Technologies 2006

  18. MainMenu, OpenFileDialog, SaveFileDialog CheckBox ComboBox TrackBar GroupBox Buttons TextBox • Main window of Mu-term .NET Technologies 2006

  19. ListView ListBox TextBox • Other windows of Mu-term .NET Technologies 2006

  20. A .NET version of Mu-term • We have developed a new (hybrid) version of Mu-term, which has the same functionality but a new GUI written in C# • Mu-term is available at: http://www.dsic.upv.es/~slucas/csr/termination/muterm/ .NET Technologies 2006

  21. Conclusions • We have shown how to integrate software components developed in Haskell together with (graphic) components developed in a .NET language such as C# • We have demonstrated the practicality of this approach by giving a new .NET GUI to Mu-term .NET Technologies 2006

  22. Thanks for your attention! .NET Technologies 2006

More Related