Monday, September 17, 2007
Clean: Hashtable and Heap
I implemented hashtables and heaps in clean.
Hashtables are data structures to store pairs of keys and values and to search values with given keys in a efficient way.
Heaps are data structures to store values and retrieve them in a decreasing (or increasing) order.
Both data structures have unique types because they are imperative data structures
repository: https://cleanoptenv.svn.sourceforge.net/svnroot/cleanoptenv/trunk/AltEnv/Data/
Hashtables are data structures to store pairs of keys and values and to search values with given keys in a efficient way.
Heaps are data structures to store values and retrieve them in a decreasing (or increasing) order.
Both data structures have unique types because they are imperative data structures
repository: https://cleanoptenv.svn.sourceforge.net/svnroot/cleanoptenv/trunk/AltEnv/Data/
Saturday, September 08, 2007
Clean : PartialReader
I created PartialReader module using Reference type.
https://cleanoptenv.svn.sourceforge.net/svnroot/cleanoptenv/trunk/AltEnv/IO/
The following program is a program which read each line from a given file and write the first 10 lines to standard output.
However, it is not suitable for a large file because it reads not only the first 10 lines but also all of the remaining lines before closing the file handle. PartialReader module is a solution for the problem.
PartialReader module internally uses Reference module and separates a reader handle and a close handle out of the given input stream. The new reader handle is used only for reading bytes and the new close handle only for closing the handle.
PartialReader module defines a useful function 'partialReadLines' that takes an input stream and returns all the lines of the stream and a close handle of the stream. Because both of the return values are lazy ones, unnecessary read actions does not take place.
https://cleanoptenv.svn.sourceforge.net/svnroot/cleanoptenv/trunk/AltEnv/IO/
The following program is a program which read each line from a given file and write the first 10 lines to standard output.
module TestThis program works well for a small file. It reads one line, writes the line and repeats the process 10 times. In favor of lazy evaluation strategy, it uses no more memory than to hold only one line.
extension for-notation
import File, StdIO, List, System
Start w
= for w
? Pass f <- openFileReader path
out <- stdio
(ls,f) = readLines f
out = loop 1 (take 10 ls) out
? PassV <- close out
? PassV <- close f
return
except (Fail msg)
return
where
path = getCommandLine.[1]
loop n [] out = out
loop n [a:aa] out
= for out
? PassV <- write n $> write " => " $> writeln a
continue loop (n + 1) aa
except (Fail msg)
return
However, it is not suitable for a large file because it reads not only the first 10 lines but also all of the remaining lines before closing the file handle. PartialReader module is a solution for the problem.
PartialReader module internally uses Reference module and separates a reader handle and a close handle out of the given input stream. The new reader handle is used only for reading bytes and the new close handle only for closing the handle.
PartialReader module defines a useful function 'partialReadLines' that takes an input stream and returns all the lines of the stream and a close handle of the stream. Because both of the return values are lazy ones, unnecessary read actions does not take place.
Start w
= for w
? Pass f <- openFileReader path
out <- stdio
(ls,f) = partialReadLines f // <- change only this line and unnecessary read actions will not take place.
out = loop 1 (take 10 ls) out
? PassV <- close out
? PassV <- close f
return
except (Fail msg)
return
Thursday, September 06, 2007
Clean: Alternative Environment
I am now working on creating AltEnv library which redefines StdEnv and other libraries so that we can use Clean in some smarter way.
Most of basic value operations are inherited directly from StdEnv. So is Maybe type.
List functions are redefined so that lazy list and strict lists can be manipulated in the same functions.
I defined deque operations and integrate operations for list and array in the same type classes.
Functions of standard IO and file IO are redefined. In the original version those handles are all of the same type but I think the types of those handles should be distinguished and I redefined them in the way.
You can get the library in the subverson repository: https://cleanoptenv.svn.sourceforge.net/svnroot/cleanoptenv/trunk/AltEnv/
Most of basic value operations are inherited directly from StdEnv. So is Maybe type.
List functions are redefined so that lazy list and strict lists can be manipulated in the same functions.
I defined deque operations and integrate operations for list and array in the same type classes.
Functions of standard IO and file IO are redefined. In the original version those handles are all of the same type but I think the types of those handles should be distinguished and I redefined them in the way.
You can get the library in the subverson repository: https://cleanoptenv.svn.sourceforge.net/svnroot/cleanoptenv/trunk/AltEnv/
Sunday, August 19, 2007
Clean: Finger trees and String2
I made an implementation of Finger trees algorithm in Clean.
Finger trees are persistent sequence data structures which support access to the ends in amortized constant time and concatenation and splitting in time logarithmic in the size of the smaller piece. see http://www.soi.city.ac.uk/~ross/papers/FingerTree.html.
As an application I also made an alternative implementation for string representation. Its performance of manipulating ordinary size strings is only 1.5 to 2 times slower than that of arrays of chars and that for long strings much more efficient.
The idea of creating an efficient string representation for long strings is inspired by the ICFP contest 2007.
FinterTree module is available at https://cleanoptenv.svn.sourceforge.net/svnroot/cleanoptenv/trunk/AltEnv/Data/.
String2 module is available at https://cleanoptenv.svn.sourceforge.net/svnroot/cleanoptenv/trunk/AltEnv/Text/.
Finger trees are persistent sequence data structures which support access to the ends in amortized constant time and concatenation and splitting in time logarithmic in the size of the smaller piece. see http://www.soi.city.ac.uk/~ross/papers/FingerTree.html.
As an application I also made an alternative implementation for string representation. Its performance of manipulating ordinary size strings is only 1.5 to 2 times slower than that of arrays of chars and that for long strings much more efficient.
The idea of creating an efficient string representation for long strings is inspired by the ICFP contest 2007.
FinterTree module is available at https://cleanoptenv.svn.sourceforge.net/svnroot/cleanoptenv/trunk/AltEnv/Data/.
String2 module is available at https://cleanoptenv.svn.sourceforge.net/svnroot/cleanoptenv/trunk/AltEnv/Text/.
Sunday, August 12, 2007
Clean : for-notation
A new extension for CleanX was released. It is for-notation extension.
The extension helps writing programs with unique typing.
Here is a sample program.
The extension helps writing programs with unique typing.
Here is a sample program.
hello f =This program will be interpreted as the following.
for f
fwrites "your name? "
s <- freadline
s = chop s
fwrites "Hello, " $> s $> newline
return
hello f # f = f |> fwrites "your name? "See more details at the site: installation of CleanX, features of for-notation
(s,f) = f |> freadline
s = chop s
f = f |> fwrites "Hello, " $> s $> newline
= f
Wednesday, August 01, 2007
Wrong subversion repository url
The url I previously wrote in this blog as my subversion repository url was found wrong.
The correct one is https://cleanoptenv.svn.sourceforge.net/svnroot/cleanoptenv.
The correct one is https://cleanoptenv.svn.sourceforge.net/svnroot/cleanoptenv.
Tuesday, July 31, 2007
Clean Wiki
I posted several issues to Clean Wiki these days.
Installation
Usage of CleanX
Installation
- Clean system
- Directory library
- OptEnv library
- CleanX system (preprocessor)
- MySQL 5.0 binding library
- SQLite 3 binding library
Usage of CleanX