<div dir="ltr"><div style="text-align:left">toList :: String -> [Integer]</div><div style="text-align:left">toList input = read ("[" ++ input ++ "]")</div><div><br></div><div>That was creative, but a more idiomatic way to write that would be to use the split package</div><div><br></div><div>stack ghci --package split<br></div><div><br></div><div>import Data.Split</div><div><br></div><div>toList :: String -> [Integer]</div><div>toList = fmap read . splitOn ","</div><div><br></div><div>As for how to aggregate times, start thinking about the types before you start. Each iteration you should take a List and return a TimeSpec.</div><div><br></div><div>testcase :: [Integer] -> IO TimeSpec</div><div>testcase l = do</div><div> start <- getTime Monotonic<br></div><div> evaluate (mergesort l)</div><div><span class="gmail-im"> end <- getTime Monotonic</span></div><div><span class="gmail-im"> return $ diffTimeSpec start end</span></div><div><span class="gmail-im"><br></span></div><div><span class="gmail-im">Now, we need to run it 100 times and collect the times. Sounds like a job for map, but since testcase is monadic, use mapM instead (or traverse).<br></span></div><div><span class="gmail-im"><br></span></div><div><span class="gmail-im">main = do<br></span></div><div><span class="gmail-im"> unsortedList <- undefined<br></span></div><div><span class="gmail-im"> times <- mapM (\c -> testcase </span>unsortedList) [1..100]</div><div> print times<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 9, 2018 at 9:40 AM, Awsaf Rahman <span dir="ltr"><<a href="mailto:awsafrahman1704@gmail.com" target="_blank">awsafrahman1704@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Okay, here is what I am trying to do. I am trying to time this mergesort program. I want to run this program 100, 1000, etc times and store the timing results in a list if possible. Can't seem to figure out how to do it! The following program prints the timings to the shell and I need to figure out a way to store the timings in a list.<div><br><div><br></div><div><div style="text-align:center">{-# LANGUAGE OverloadedStrings #-}</div><div style="text-align:center">{-# LANGUAGE BangPatterns #-}</div><div style="text-align:center">import Control.Exception</div><div style="text-align:center">import Formatting</div><div style="text-align:center">import Formatting.Clock</div><div style="text-align:center">import System.Clock</div><div style="text-align:center">import Control.DeepSeq</div><div style="text-align:center"><br></div><div style="text-align:center">mergesort [] = []</div><div style="text-align:center">mergesort [x] = [x]</div><div style="text-align:center">mergesort xs = let (lhalf, rhalf) = splitAt (length xs `div` 2) xs</div><div style="text-align:center"> in merge' (mergesort lhalf) (mergesort rhalf)</div><div style="text-align:center"><br></div><div style="text-align:center">merge' lhalf rhalf = merge lhalf rhalf []</div><div style="text-align:center"><br></div><div style="text-align:center">merge [] [] acc = reverse acc</div><div style="text-align:center">merge [] y acc = reverse acc ++ y</div><div style="text-align:center">merge x [] acc = reverse acc ++ x</div><div style="text-align:center"><br></div><div style="text-align:center">merge (l:ls) (r:rs) acc</div><div style="text-align:center"> | l < r = merge ls (r:rs) (l:acc)</div><div style="text-align:center"> | otherwise = merge rs (l:ls) (r:acc)</div><div style="text-align:center"><br></div><div style="text-align:center">toList :: String -> [Integer]</div><div style="text-align:center">toList input = read ("[" ++ input ++ "]")</div><div style="text-align:center"><br></div><div style="text-align:center">repeater unsortedlist 0 result = return (result)</div><div style="text-align:center"><br></div><div style="text-align:center">repeater unsortedlist counter result = do</div><div style="text-align:center"> start <- getTime Monotonic</div><div style="text-align:center"> evaluate(mergesort unsortedlist)</div><span class=""><div style="text-align:center"> end <- getTime Monotonic</div><div style="text-align:center"> fprint (timeSpecs % "\n") start end</div></span><div style="text-align:center"> repeater unsortedlist (counter-1) result</div><div style="text-align:center"><br></div><div style="text-align:center">main = do</div><div style="text-align:center"> file <- getLine</div><div style="text-align:center"> contents <- readFile file</div><div style="text-align:center"> let !unsortedlist = (toList contents)</div><div style="text-align:center"> repeater unsortedlist 100 []</div></div><div style="text-align:center"><br></div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 9, 2018 at 3:21 PM, David McBride <span dir="ltr"><<a href="mailto:toad3k@gmail.com" target="_blank">toad3k@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I guess whatever version you are using did not export that function. In any case the definition for that function is incredibly simple, so you could just write your own for now.<br></div><div><br></div><div><pre><span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-definition">diffTimeSpec</span> <span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-keyglyph">::</span> <span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-conid">TimeSpec</span> <span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-keyglyph">-></span> <span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-conid">TimeSpec</span> <span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-keyglyph">-></span> <span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-conid">TimeSpec</span>
<a name="m_-4804885380657410196_m_-1435225354693086097_line-285"></a><span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-definition">diffTimeSpec</span> <span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-varid">ts1</span> <span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-varid">ts2</span> <span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-keyglyph">=</span> <span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-varid">abs</span> <span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-layout">(</span><span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-varid">ts1</span> <span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-comment">-</span> <span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-varid">ts2</span><span class="m_-4804885380657410196m_-1435225354693086097gmail-hs-layout">)</span>
<a name="m_-4804885380657410196_m_-1435225354693086097_line-286"></a></pre><br></div></div><div class="m_-4804885380657410196HOEnZb"><div class="m_-4804885380657410196h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 9, 2018 at 9:08 AM, Awsaf Rahman <span dir="ltr"><<a href="mailto:awsafrahman1704@gmail.com" target="_blank">awsafrahman1704@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I imported the System.Clock module and tried to use the diffTimeSpec function but it keeps saying "out of scope". </div><div class="m_-4804885380657410196m_-1435225354693086097HOEnZb"><div class="m_-4804885380657410196m_-1435225354693086097h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 9, 2018 at 2:45 PM, David McBride <span dir="ltr"><<a href="mailto:toad3k@gmail.com" target="_blank">toad3k@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">There is a <a id="m_-4804885380657410196m_-1435225354693086097m_-892014508039423581m_-1289026758857823126gmail-v:diffTimeSpec" class="m_-4804885380657410196m_-1435225354693086097m_-892014508039423581m_-1289026758857823126gmail-def">diffTimeSpec</a> function in that module that seems like it would work.<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-4804885380657410196m_-1435225354693086097m_-892014508039423581h5">On Mon, Jul 9, 2018 at 8:30 AM, Awsaf Rahman <span dir="ltr"><<a href="mailto:awsafrahman1704@gmail.com" target="_blank">awsafrahman1704@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_-4804885380657410196m_-1435225354693086097m_-892014508039423581h5"><div dir="ltr">Hello, <div><br></div><div>I am trying to time a function I have written in haskell using the clock package in the following way: </div><div><br></div><div><div style="text-align:center"><b>start <- getTime Monotonic</b></div><div style="text-align:center"><b>evaluate(something)</b></div><div style="text-align:center"><b>end <- getTime Monotonic</b></div><div style="text-align:center"><b>fprint (timeSpecs % "\n") start end</b></div></div><div style="text-align:center"><br></div><div style="text-align:left"><br></div><div style="text-align:left">Now what I want is to store the time difference between <b>start</b> and <b>end. </b>Is there a way I can do that? </div><div style="text-align:left"><br></div><div style="text-align:left">Regards </div><span class="m_-4804885380657410196m_-1435225354693086097m_-892014508039423581m_-1289026758857823126HOEnZb"><font color="#888888"><div style="text-align:left">Awsaf</div></font></span></div>
<br></div></div>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">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-bi<wbr>n/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>
<br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">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-bi<wbr>n/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">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-bi<wbr>n/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">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-bi<wbr>n/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<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-<wbr>bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>