Hi Luke,

There are a couple of errors in your program.

First, the error message is about the use of File in the type class constraint (... | FileSystem File). You pass it the File argument, but it should be a type variable. The following signature removes this error:

readzipcode :: String *files -> ((Int, Char, Char), *files) | FileSystem files

This expresses that your function readzipcode works for any type files provided that it supports the operations defined in the type class FileSystem.

Second, the three lines with freadi, freadc, and freadc are incompatible with the fact that you've just opened a read-only file with sfopen. To read from read-only files you need their twin functions sfreadi and sfreadc.

Third, you need to 'thread along' the altered read-only file versions. In your current function you would keep reading from the same position of the same 'infile' value. The idiom for that is indeed the #-let notation, and you'd get:

# (b1, i, infile) = sfreadi infile
# (b2, c1, infile) = sfreadc infile
# (b3, c2, infile) = sfreadc infile

Fourth, to avoid partial functions, I'd prefer an otherwise case at the end of your function to catch failing reads, similar to the earlier catch that you've written.

Hope this helps,
Peter

On 7/1/2014 12:14 AM, Luke Immes wrote:
Quick question; program will not compile; and I tried for hours to get it to work.
Any help would be appreciated.
All I want is to read text from a file...; thanks.

clean 515>make

clm -h 20m zip -o zip

Compiling zip

Error [zip.icl,6,readzipcode]: FileSystemM:11 type context should contain one or more type variables

make: *** [zip] Error 1

clean 515>

----------------
module zip

import StdEnv, StdFile, StdOrdList, StdList, StdInt, StdReal
inputfilename :== "zip.txt"

readzipcode :: String *File -> ((Int, Char, Char), *File) | FileSystem File
readzipcode inputfilename files
# (readok, infile, files) = sfopen inputfilename FReadText files
| not readok = abort ("Cannot open input file: '" +++ inputfilename +++ "'")
# (b1, i, files) = freadi infile
# (b2, c1, files) = freadc infile
# (b3, c2, files) = freadc infile
| (b1 && b2 && b3) = ((i, c1, c2), files)

Start :: *World -> ((Int, Char, Char), *World)
Start ((int, ch1, ch2), world) = readzipcode inputfilename world




_______________________________________________
clean-list mailing list
[email protected]
http://mailman.science.ru.nl/mailman/listinfo/clean-list

_______________________________________________
clean-list mailing list
[email protected]
http://mailman.science.ru.nl/mailman/listinfo/clean-list

Reply via email to