[clean-list] Problems with opening a file to read [Char]

Sander van den Berg xkb@hypernation.net
Sun, 5 Sep 2004 16:41:52 +0200


Hello list.

Im trying to open a text file to read its contents to a string. The 
following code is what I have now:

module filetest

import StdEnv


openFile :: String *env -> (File, *env)
openFile inputfname filesys
	| not readok 	= abort ("error")
	| otherwise		= (inputfile, touchedfs)
where
	(readok, inputfile, touchedfs) = sfopen inputfname FReadText filesys

readChar :: File -> [Char]
readChar f
	| not readok 	= []
	| otherwise		= [ char : readChar alteredfile ]
where
	(readok,char,alteredfile) = sfreadc f



//open a file, read the chars and print them
Start :: *world -> *world
Start world
	#	(console, world)= stdio world
		console 		= fwrites ((readChar o fst) (openFile "filetest.icl" 
world)) console
		(ok,console)	= fclose console world
	|	not ok			= abort "Cannot close console"
	|	otherwise		= world


This code is inspired by the code in the Clean book. The problem I have 
with it are as follows:

-How do I get a File to pass to readChar.
-The error I get compiling is: internal overloading of "sfopen" could 
not be resolved. I dont overload it?
-How do you construct a string, as in Clean String != [Char] according 
to the compiler messages.

Regards,

Sander.