<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:'times new roman', 'new york', times, serif;font-size:10pt"><div><span class="Apple-style-span" style="font-family: Tahoma; font-size: 11px; white-space: pre-wrap; ">Hi ..

Hope you are doing well . I've just joined this group coz I am really a beginner and have no idea that what I have to do !</span></div><div><span class="Apple-style-span" style="font-family: Tahoma; font-size: 11px; white-space: pre-wrap; "> 
Recently, I am  struggling to do some simple experiment with haskell language about parallelism and wrong answers that we can get while using a shared variable .</span></div><div><span class="Apple-style-span" style="font-family: Tahoma; font-size: 11px; white-space: pre-wrap; ">
I tried to write a simple program, for example calculationg 'n=n+1' few times.And then I tried to do it in parallel by using 'par' and 'pseq' . The aim was to get the wrong answer because we have to share a variable here,and without using 'MVar' function we will get the wrong answer for the calculation .</span></div><div><font class="Apple-style-span" face="Tahoma" size="3"><span class="Apple-style-span" style="font-size: 11px; white-space: pre-wrap;"><br></span></font></div><div><span class="Apple-style-span" style="font-family: Tahoma; font-size: 11px; white-space: pre-wrap; ">I don't know how to write it in parallel in order to get a wrong answer when we don't use MVar,because we have a shared variable here. I read about MVars as well,but also I don't know how to combine MVar and Par together to get the program to work.</span></div><div><font class="Apple-style-span" face="Tahoma" size="3"><span class="Apple-style-span" style="font-size: 11px;
 white-space: pre-wrap;"><br></span></font></div><div><span class="Apple-style-span" style="font-family: Tahoma; font-size: 11px; white-space: pre-wrap; ">I wrote this :</span></div><div><font class="Apple-style-span" face="Tahoma" size="3"><span class="Apple-style-span" style="font-size: 11px; white-space: pre-wrap;"><br></span></font></div><div><span class="Apple-style-span" style="font-family: Tahoma; font-size: 11px; white-space: pre-wrap; ">module Main where

f :: Int -> Int -> Int
f i n = g 1 i n
  where g x i n | x &lt;= i = g (x+1) i (n+1)
                | otherwise = n

main :: IO ()
main =
  do putStrLn "starting..."
     let r = f 10 5
     putStrLn (show r)
     putStrLn "finished"
<br></span></div><div><span class="Apple-style-span" style="font-family: Tahoma; font-size: 11px; white-space: pre-wrap; ">I want to make to work in parallel by using 'Par'.And also use MVar for this simple example to work.</span></div><div><span class="Apple-style-span" style="font-family: Tahoma; font-size: 11px; white-space: pre-wrap; ">All of the example about MVar are a little bit complicated and I couldn't figure it that how can I write one,the same !</span></div><div><font class="Apple-style-span" face="Tahoma" size="3"><span class="Apple-style-span" style="font-size: 11px; white-space: pre-wrap;"><br></span></font></div><div><span class="Apple-style-span" style="font-family: Tahoma; font-size: 11px; white-space: pre-wrap; ">Can any one help me with this ? I want a simple example that I can feel the need of MVar when I run my program in parallel and while I am using a shared variable.</span></div><div><br></div><div><span class="Apple-style-span"
 style="font-family: Tahoma; font-size: 11px; white-space: pre-wrap; ">Regards;
Mozhgan
</span></div><div><font class="Apple-style-span" face="Tahoma" size="3"><span class="Apple-style-span" style="font-size: 11px; white-space: pre-wrap;"><br></span></font></div><div style="position:fixed"></div></div><br>

      </body></html>