Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Simple IO actions can be combined into more advanced ones by using do notation.</p> <pre><code>main = do printStrLn "Hello" printStrLn "World" </code></pre> <p>combines the IO action <code>printStrLn "Hello"</code> with the IO action <code>printStrLn "World"</code>. Main is now an IO action first printing a line that says "Hello" and then a line that says "World". Written without do-notation (which is just syntactic suger) it looks like this:</p> <pre><code>main = printStrLn "Hello" &gt;&gt; printStrLn "World" </code></pre> <p>Here you can see the <code>&gt;&gt;</code> function combining the two actions.</p> <p>You can create an IO action that reads a line, passes it to a function(that does awesome stuff to it :)) and the prints the result like this:</p> <pre><code>main = do input &lt;- getLine let result = doAwesomeStuff input printStrLn result </code></pre> <p>or without binding the result to a variable:</p> <pre><code>main = do input &lt;- getLine printStrLn (doAwesomeStuff input) </code></pre> <p>This can ofcourse also be written as IO actions and functions that combine them like this:</p> <pre><code>main = getLine &gt;&gt;= (\input -&gt; printStrLn (doAwesomeStuff input)) </code></pre> <p>When you run the program the main IO action is executed. This is the only time any IO actions are actually executed. (well technically you can also execute them within you program, but it is not safe. The function that does the is called <code>unsafePerformIO</code>.)</p> <p>You can read more here: <a href="http://www.haskell.org/haskellwiki/Introduction_to_Haskell_IO/Actions" rel="nofollow">http://www.haskell.org/haskellwiki/Introduction_to_Haskell_IO/Actions</a></p> <p>(This link is probably a better explaination than mine, but I only found it after I had written nearly everything. It is also quite a bit longer)</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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