You could try this:

--OpenFile.hs
module OpenFile where
import IOExts

openfile :: String -> String
openfile =  unsafePerformIO . readFile
-- end of file

> -----Original Message-----
> From: Hamilton Richards [mailto:[EMAIL PROTECTED]]
> Sent: 26 April 2000 14:04
> To: [EMAIL PROTECTED]
> Subject: openfile :: String -> String
> 
> 
> The Gofer prelude had a function
> 
>       openfile :: String -> String
> 
> which mapped file path names to strings containing the named 
> files' contents.
> 
> The Hugs98 Prelude doesn't seem to have anything like that function.
> Instead, it has things like
> 
>       readFile :: String -> IO String
> 
> Why would I want openfile instead of readFile? The problem in 
> which the
> need for openfile arose is this:
> 
>    I want to load a binary search tree and a list with
>    words read from a file, and then perform, interactively,
>    several tests comparing the cost of searching the
>    tree with that of searching the list. In addition to
>    performing the tests interactively, I want to separate
>    the cost of searching the list and the tree from the
>    cost of constructing them.
> 
> In order for the list and the tree to be used in several successive
> command-line evaluations without being reconstructed each 
> time, they must
> be named globally. This is no problem with openfile, but 
> readFile forces
> their names to be local to an IO command.
> 
> Can anyone suggest a solution?
> 
> Thanks,
> 
> --Ham
> 
> 
> 
> ------------------------------------------------------------------
> Hamilton Richards Jr.            Department of Computer Sciences
> Senior Lecturer                  Mail Code C0500
> 512-471-9525                     The University of Texas at Austin
> SHC 434                          Austin, Texas 78712-1188
> [EMAIL PROTECTED]
> ------------------------------------------------------------------
> 
> 
> 

Reply via email to