Note that there are some explanatory texts on larger screens.

plurals
  1. POUnwrapping a monad
    primarykey
    data
    text
    <p>Given the below program, I am having issues dealing with monads.</p> <pre><code>module Main where import System.Environment import System.Directory import System.IO import Text.CSV -------------------------------------------------- exister :: String -&gt; IO Bool exister path = do fileexist &lt;- doesFileExist path direxist &lt;- doesDirectoryExist path return (fileexist || direxist ) -------------------------------------------------- slurp :: String -&gt; IO String slurp path = do withFile path ReadMode (\handle -&gt; do contents &lt;- hGetContents handle last contents `seq` return contents ) -------------------------------------------------- main :: IO () main = do [csv_filename] &lt;- getArgs putStrLn (show csv_filename) csv_raw &lt;- slurp csv_filename let csv_data = parseCSV csv_filename csv_raw printCSV csv_data -- unable to compile. </code></pre> <p>csv_data is an Either (parseerror) CSV type, and printCSV takes only CSV data.</p> <hr> <p>Here's the ediff between the working version and the broken version.</p> <pre><code>*************** *** 27,30 **** csv_raw &lt;- slurp csv_filename let csv_data = parseCSV csv_filename csv_raw ! printCSV csv_data -- unable to compile. \ No newline at end of file --- 27,35 ---- csv_raw &lt;- slurp csv_filename let csv_data = parseCSV csv_filename csv_raw ! case csv_data of ! Left error -&gt; putStrLn $ show error ! Right csv_data -&gt; putStrLn $ printCSV csv_data ! ! putStrLn "done" ! </code></pre> <p>reference: <a href="http://hackage.haskell.org/packages/archive/csv/0.1.2/doc/html/Text-CSV.html" rel="nofollow">http://hackage.haskell.org/packages/archive/csv/0.1.2/doc/html/Text-CSV.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload