Clean language: read the content of text file to list of lines. Is it possible to avoid Uniqueness?

63 views Asked by At

Assuming I have *File that I want to read its whole content, and store each line as different element in a list.

My intuitive solution was:

first (x,y) = x

readFile:: *File -> [{#Char}]
readFile file 
    | first (fend (file))   = []
    | otherwise             = [ line : readFile (file)] 
where
    line = first(freadline (file))

Both freadline and fend come from StdFile module:

/**
 * Reads a line from a textfile, including a newline character, except for     the
 * last line. `freadline` cannot be used on data files.
 */
freadline   :: !*File -> (!*{#Char},!*File)

/**
 * @result Whether end-of-file has been reached
 */
fend        :: !*File -> (!Bool,!*File)

But ofcourse I got error since I violated some Uniquness rules:

file demanded attribute cannot be offerd by shared object.

How to avoid this Uniquness problem? I've tried using where to store the value of one freadline, but apparently it doesn't work.

Please consider the fact that I'm new to Clean and the rules of Uniqueness are not very clear to me. Thanks a lot!

0

There are 0 answers