Presentation is loading. Please wait.

Presentation is loading. Please wait.

Building.NET GUIs for Haskell applications Beatriz Alarcón Jiménez

Similar presentations


Presentation on theme: "Building.NET GUIs for Haskell applications Beatriz Alarcón Jiménez"— Presentation transcript:

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

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

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

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

5 .NET Technologies 2006 Overview of.NET graphic controls System.Windows.Forms namespace System.Windows.Forms namespace.NET controls and data.NET controls and data Button, GroupBox, Panel, Label, Splitter - CheckBox, RadioButton Bool ListBox([Int],[String]) ComboBox(Int,[String]) ListView[[String]] TrackBar, ProgressBar, NumericUpDown Int TextBox, Rich TextBox String MainMenu, OpenFileDialog, SaveFileDialog, FolderBrowserDialog _

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

7 .NET Technologies 2006 A simple case study In the Haskell part (Hlist.hs): 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

8 .NET Technologies 2006 Interoperability by means of COM in Haskell A Haskell program that implements a COM component consists of four parts: A Haskell program that implements a COM component consists of four parts: The application code, written in Haskell by the programmer 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 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 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) 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)

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

10 .NET Technologies 2006 The IDL of the Haskell Component IDL is a declarative language to describe the interface of a 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 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: The interface for the function deleteB extracted from example.idl: HRESULT deleteB();

11 .NET Technologies 2006 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 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: Regarding the definition of the skeleton, HDirect accomplishes the following tasks: To import the necessary Haskell modules 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 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 To include Haskell declarations corresponding to the funtions defined in the IDL

12 .NET Technologies 2006 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 () -> Prelude.IO () deleteB (State st) = do { hl <- readIORef st hl <- readIORef st ; str' <- Prelude.return (HList.deleteB (HList.getString hl)) ; str' <- Prelude.return (HList.deleteB (HList.getString hl)) ; writeIORef st (HList.writeString str' hl) ; writeIORef st (HList.writeString str' hl)}(…)

13 .NET Technologies 2006 Creating a COM DLL from Haskell modules After compiling these modules, it is necessary to provide a Main module. 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) 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 We must bind the type library to our DLL Now, we can build the DLL including all compiled modules of the application Now, we can build the DLL including all compiled modules of the application

14 .NET Technologies 2006 Integration of COM into.NET Register the DLL (regsvr32.exe) Register the DLL (regsvr32.exe) The data types, error management,…are different for managed and unmanaged objects 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 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 Now, in VS.NET, we can add the generated assembly as reference in our Windows application

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

16 .NET Technologies 2006 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();} Example.cs Example.cs

17 .NET Technologies 2006 A.NET version of Mu-term Mu-term is a termination proof tool for (Context-Sensitive) Rewriting Systems 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 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 The system consists of around 30 Haskell modules containing more than 5000 lines of code

18 .NET Technologies 2006 Main window of Mu-term Main window of Mu-term ButtonsTextBox MainMenu, OpenFileDialog, SaveFileDialog GroupBoxTrackBar ComboBoxCheckBox

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

20 .NET Technologies 2006 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# 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/ Mu-term is available at: http://www.dsic.upv.es/~slucas/csr/termination/muterm/

21 .NET Technologies 2006 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 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 We have demonstrated the practicality of this approach by giving a new.NET GUI to Mu-term

22 .NET Technologies 2006 Thanks for your attention!


Download ppt "Building.NET GUIs for Haskell applications Beatriz Alarcón Jiménez"

Similar presentations


Ads by Google