newline - Haskell new line not working -


been messing around 20 minutes trying new line working shows in ghci single line.

here enter ghci:

displayfilm ("skyfall",["daniel craig", "judi dench", "ralph fiennes"], 2012, ["bill", "olga", "zoe", "paula", "megan", "sam", "wally"]) 

here printed:

"skyfall----------\n cast: daniel craig, judi dench, ralph fiennes\n year: 2012\n fans: 7\n"

displaylist :: [string] -> string displaylist [] = "" displaylist [x] = x ++ "" ++  displaylist [] displaylist (x:xs) = x ++ ", " ++ displaylist xs   displayfilm :: film -> string displayfilm (title, cast, year, fans) =      title ++ "----------" ++     "\n cast: " ++ (displaylist cast) ++     "\n year: " ++ (show year) ++     "\n fans: " ++ show (length fans) ++ "\n" 

to print string is, without escaping special characters, use:

putstr string 

or

putstrln string 

if want newline @ end. in case, looking for

putstr (displayfilm (....)) 

why needed? in ghci, if evaluate expression s result printed if running print s (unless has type io something -- forget special case). if e string, print escapes special characters , output result. because print meant output string syntax follows 1 in haskell expressions. numbers, usual decimal notation. strings, quotes , escaped characters.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -