Note that there are some explanatory texts on larger screens.

plurals
  1. PONested `do` blocks in Haskell
    primarykey
    data
    text
    <p>I'm trying to write a function in Haskell which checks for some things and then recurses based on some minimal user input. In order to do that I think I have to use <code>do</code> blocks.</p> <pre><code>cip :: [Argument] -&gt; [Argument] -&gt; Bool -&gt; Bool -&gt; IO() cip (a:args) pargs burden gameover = do let nasko = a:pargs putStrLn (getPremise a) let newgraph = Carneades.mkArgGraph nasko let newcaes = (CAES (newgraph,audience2,assStandarts)) let answer = (acceptable (mkProp (getPremise a)) newcaes ) print answer if(answer==True) then (cip args nasko burden gameover) else do print "One of the arguments is not proved. Here are the premises that need proving" print (propsForFixing newcaes a) print "Let's see what you have for the first Propositon" --add an if to check if no applicable arguments. print (argumentScanHelp (head (propsForFixing newcaes a)) args) print "\n Would you like me to apply the firt one? Y/N" choice &lt;- getLine if(choice=="Y") then do print "applying the argument" let applicabee = head (argumentScanHelp (head (propsForFixing newcaes a)) args) print "Argument targeted" let newargs = delete applicabee args let newpargs = applicabee:nasko print "Argument applied sucsessfuly. Recusing again" (cip newargs newpargs burden gameover) return() </code></pre> <p>It hurts my eyes just by looking at it, but that's <code>do</code> blocks for you. Everything up to the third <code>do</code> block is okay. But then on this line:</p> <pre><code> if(choice=="Y") then do print "applying the argument" let applicabee = head (argumentScanHelp (head (propsForFixing newcaes a)) args) </code></pre> <p>The complier starts crying:</p> <pre><code>Main.hs:209:73: parse error on input `let' </code></pre> <p>Tried a all kinds of different indentations but I can't seem to get it to work. I don't want to use separate functions, because that means I'll have to pass a lot of arguments around constantly.</p> <p>Can anyone help me get it right? Also an explanation of what exactly the specifications for nested <code>do</code> block are would be greatly appreciated. </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.
    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