<div dir="ltr">Is your intent is to call main function? How do you compile this module, is it part of a bigger project, or just a single-file program? If single-file -- rename main to something else, then create a main function which has a type "main :: IO ()", and put something like:<div><br></div><div> main :: IO ()</div><div> main = print (mainRoutine 10 5)</div><div><br></div><div>It'll call mainRoutine with 10 and 5 args and print its result. You can then run it with "runhaskell MyProg.hs"</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 13, 2015 at 7:14 PM, Imants Cekusins <span dir="ltr"><<a href="mailto:imantc@gmail.com" target="_blank">imantc@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This snippet increments integer n times using state monad.<br>
<br>
How to call:<br>
main 10 5<br>
<br>
<br>
<br>
<br>
module BasicState where<br>
<br>
import Control.Monad.State.Strict<br>
import Debug.Trace<br>
<br>
type St a = State a a<br>
<br>
<br>
-- caller is not aware that main uses state<br>
-- mai is a pure function<br>
main :: Int -> Int -> Int<br>
main start0 repeat0 =<br>
evalState (repeatN repeat0) start0<br>
<br>
<br>
-- state-passing computation<br>
repeatN :: Int -> St Int<br>
repeatN n0 -- repeat n times<br>
| n0 < 1 = get -- current state<br>
| otherwise = do<br>
withState pureStateModifier get -- update state<br>
repeatN $ n0 - 1 -- recurse<br>
<br>
<br>
-- state unaware modifier function<br>
pureStateModifier :: Int -> Int<br>
pureStateModifier = (+ 1)<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>