hendl <- openFile fileName ReadMode loadFacts <- hGetContents hendl qs <- return (table (read loadFacts)) run qs hClose hendl
here is a fragment of the function, please explain what reads and returns do here
If anything, here are the rub and table definitions
run::Table -> IO () table::Facts->Table
@alexlz I still have a question about the read function - we pass it a pointer to the file, and it reads it (the table function has the form
table::Facts->Table, где type Fact = (String,[(String,Bool)]) type Facts = [Fact] ) а входной файл имеет вид [("aa1", [("bb", True), ("cc", False),]), ("aa2", [("bb", True), ("cc", True),])]
And how is reading? Line by line or every tuple reads?
read :: Read a => String -> a
, the result is of typea
, in your case Facts. Reading a file from you is hGetContents. You canread
andshow
override for your data type (I don’t remember abouttype
aliases, maybe not). So it reads everything at once. By the way, do you have commas there? (before square brackets). Although, I don’t know how the file is read taking into account laziness. - alexlzloadFacts
, which is the content (all - hGetContents) of fileName. ("immediately" is in the process of work, do not forgethGetContents :: Handle -> IO String
)hGetContents :: Handle -> IO String
. And loadFacts is of type String. Parsing and converting to a value of type Facts performs a read. - alexlzseq
,$!
- alexlz