Questions on converting Miranda code to Haskell 
Author Message
 Questions on converting Miranda code to Haskell

Hello,

I have written a program in Miranda (about 2000 lines), and I want to
convert it to Haskell. The program has following features and structure:

        1) Read source data from a file;
        2) Manipulate the source data and generate some global values;
        3) There are a number of computation modules which all access
           the global values obtained from the source data, and the
           results of some computation modules are further used in
           other computation modules.

I list the code of a small Miranda program which captures the same features
as of my original program, except that my original program got more global
values and much more computation:

| ns    = map numval (lines (read "data"))

| n     = # ns

| sqrts = map sqrt ns

| sum_sqrts = sum sqrts

| avg_sqrts = sum_sqrts / n

| men_sqrts = sum (map minus_avg_sqr sqrts) / n
|             where
|             minus_avg_sqr x = (x - avg_sqrts) * (x - avg_sqrts)

| result  = "number of values = " ++ show n ++ "\n"
|           ++ "sum_sqrts = " ++ show sum_sqrts ++ "\n"
|           ++ "avg_sqrts = " ++ show avg_sqrts ++ "\n"
|           ++ "men_sqrts = " ++ show men_sqrts ++ "\n"

| main    = [Stdout result]

The approaches which I could think of were:

        1) Add the input stream as an extra argument to every functions
           and variables, replace the expression (read "data") by the
           argument (i.e. the input stream), and change the main function
           accordingly as outlined below:

                > main = readChan "data" abort
                >     (\ s -> appendChan "stdout" (result s) abort done)

                > ns s = map read (lines s)

                > n  s = length (ns s)
                ... ...

        2) Replace the expression (read "data") by the input stream,
           change the main function accordingly and put all other function
           and variable definitions into a BIG where expression:

                > main = readChan "data" abort
                >        (\ s -> appendChan "stdout" (result s) abort done
                >             where
                >             ns = map read (lines s)
                >             n  = length ns
                >             ... ...
                >     )

        3) Or do something between the above two approaches, but not
           really add the input stream as extra argument.

Though the first two approaches are very simple and straightforward, the
approach 1 lose the sharing of global variables completely and the approach
2 can only be applied very very small program. While using the last approach
needs much more thought and may need to change the original code quite lot
depending on the program to be converted.

My questions then are:

        How can the Miranda program be easily converted to Haskell?

        Will the performance be affected in the resulting Haskell program
        in terms of preserving sharing?

        Can the approach be applied to large programs?

Thanks in advance for any help.

Please mail me and I'll summarise if there is enough interest.

Liu.
-------
Dr J Liu,   Department of Computing, Imperial College,
            180 Queens Gate, London SW7 2BZ, United Kingdom.
Telephone : (+44 71/071) 589 5111 ext. 5033  Fax : (+44 71/071) 581 8024



Fri, 06 Jan 1995 23:57:57 GMT  
 Questions on converting Miranda code to Haskell

The character '>' appeared at the first column of my original
message was automatically converted to '|' somehow (I don't know
why). I list the Miranda code here again (leave first coulmn
blank):

 > ns    = map numval (lines (read "data"))

 > n     = # ns

 > sqrts = map sqrt ns

 > sum_sqrts = sum sqrts

 > avg_sqrts = sum_sqrts / n

 > men_sqrts = sum (map minus_avg_sqr sqrts) / n
 >             where
 >             minus_avg_sqr x = (x - avg_sqrts) * (x - avg_sqrts)

 > result  = "number of values = " ++ show n ++ "\n"
 >           ++ "sum_sqrts = " ++ show sum_sqrts ++ "\n"
 >           ++ "avg_sqrts = " ++ show avg_sqrts ++ "\n"
 >           ++ "men_sqrts = " ++ show men_sqrts ++ "\n"

 > main    = [Stdout result]

Sorry about this.

Liu.
-------
Dr J Liu,   Department of Computing, Imperial College,
            180 Queens Gate, London SW7 2BZ, United Kingdom.
Telephone : (+44 71/071) 589 5111 ext. 5033  Fax : (+44 71/071) 581 8024



Sat, 07 Jan 1995 23:58:23 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Haskell, Miranda to Haskell

2. translator :: Haskell -> Miranda

3. Haskell versus Miranda

4. haskell versus Miranda

5. Haskell/Miranda efficiency difference

6. Input/output streams in Haskell and Miranda

7. mira2hs v1.03 - Miranda to Haskell convertor

8. miranda to haskell/gofer conversion

9. mira2hs - a Miranda to Haskell converter

10. mira2hs - a Miranda to Haskell converter

11. jHaskell; translating Haskell code to Java code

12. Question about converting code for Microsoft's PS v1.0 to v4.0 - Please help

 

 
Powered by phpBB® Forum Software