Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Execution time of Mergesort (KC)
2. Re: Passing a file containing a list as an input
(Olivier Revollat)
3. Re: Passing a file containing a list as an input
(Olivier Revollat)
----------------------------------------------------------------------
Message: 1
Date: Thu, 5 Jul 2018 20:29:16 -0700
From: KC <[email protected]>
To: Haskell Beginners <[email protected]>
Subject: Re: [Haskell-beginners] Execution time of Mergesort
Message-ID:
<camlkxynck7ddicnmmx8dyybbrmla_pwznopizygfkicmnm9...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Appending to lists is slow
--
Sent from an expensive device which will be obsolete in a few months
Casey
On Thu, Jul 5, 2018, 7:14 PM Awsaf Rahman, <[email protected]>
wrote:
> I did consider strictness and that is why the execution time has come down
> from 16 seconds to 12 seconds! But I can't seem to find the issue anymore!
>
> On Fri, Jul 6, 2018 at 4:06 AM, KC <[email protected]> wrote:
>
>> I haven't looked at the code much yet
>> But might want to consider strictness 😎
>>
>> --
>> Sent from an expensive device which will be obsolete in a few months
>> Casey
>>
>> On Thu, Jul 5, 2018, 7:01 PM Awsaf Rahman, <[email protected]>
>> wrote:
>>
>>> Hello everyone!
>>>
>>> I am trying to find out the execution time of mergesort for a list size
>>> of 1 million integers. I have done the same in Erlang as well and the
>>> execution time in Erlang was around 0.93 seconds. I have implemented the
>>> program in almost the same way in Haskell as well but for some reason the
>>> Haskell implementation is taking around 12 seconds which doesn't seem
>>> right.
>>>
>>> Here is the implementation in Haskell:
>>>
>>> *{-# LANGUAGE OverloadedStrings #-}*
>>> *{-# LANGUAGE BangPatterns #-}*
>>> *import Control.Exception*
>>> *import Formatting*
>>> *import Formatting.Clock*
>>> *import System.Clock*
>>> *import Control.DeepSeq*
>>>
>>> *mergesort [] = []*
>>> *mergesort [x] = [x]*
>>> *mergesort xs = let (lhalf, rhalf) = splitAt (length xs `div` 2) xs*
>>> * in merge' (mergesort lhalf) (mergesort rhalf)*
>>>
>>> *merge' lhalf rhalf = merge lhalf rhalf []*
>>>
>>> *merge [] [] acc = reverse acc*
>>> *merge [] y acc = reverse acc ++ y*
>>> *merge x [] acc = reverse acc ++ x*
>>>
>>> *merge (l:ls) (r:rs) acc*
>>> * | l < r = merge ls (r:rs) (l:acc)*
>>> * | otherwise = merge rs (l:ls) (r:acc)*
>>>
>>> *toList :: String -> [Integer]*
>>> *toList input = read ("[" ++ input ++ "]")*
>>>
>>> *main = do*
>>> * file <- getLine*
>>> * contents <- readFile file*
>>> * let !unsortedlist = (toList contents)*
>>> * start <- getTime Monotonic*
>>> * evaluate(force (mergesort unsortedlist))*
>>> * end <- getTime Monotonic*
>>> * fprint (timeSpecs % "\n") start end*
>>>
>>>
>>> What am I doing wrong?
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180705/5637731d/attachment-0001.html>
------------------------------
Message: 2
Date: Fri, 6 Jul 2018 09:33:32 +0200
From: Olivier Revollat <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Passing a file containing a list as
an input
Message-ID:
<CA+nXgrW=wl7kk_rddk3hpbibsxjbsmhz7ccbnfibcuqgxod...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi,
Maybe you should try "interact"
main = io (map processIt)
io f = interact (unlines . f . lines)
Le jeu. 5 juil. 2018 à 22:21, Awsaf Rahman <[email protected]> a
écrit :
> Hello everyone!
>
> I am really struggling with Haskell I/O.
>
> I have written a mergesort program and as an input to that program I want
> to use a file containing a list of 1000 integers. Let's say the contents of
> the file look like this
>
> [120, 400, 500 , 20, 100 ..]
>
> How can I achieve that? I am trying to write a main function that takes
> the file as an input and passes the list to my mergesort function..
>
> Regards
> Awsaf Rahman
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180706/3e6992ea/attachment-0001.html>
------------------------------
Message: 3
Date: Fri, 6 Jul 2018 09:35:47 +0200
From: Olivier Revollat <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Passing a file containing a list as
an input
Message-ID:
<ca+nxgrub-yvro8qmkfjpbdqs9qdt7wunchls3evu7xi9ok7...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
See also http://book.realworldhaskell.org/read/io.html
Example (take stdin and stdout the uppercased)
import Data.Char(toUpper)
main = interact (map toUpper)
Le ven. 6 juil. 2018 à 09:33, Olivier Revollat <[email protected]> a
écrit :
> Hi,
> Maybe you should try "interact"
>
> main = io (map processIt)
> io f = interact (unlines . f . lines)
>
>
>
> Le jeu. 5 juil. 2018 à 22:21, Awsaf Rahman <[email protected]> a
> écrit :
>
>> Hello everyone!
>>
>> I am really struggling with Haskell I/O.
>>
>> I have written a mergesort program and as an input to that program I want
>> to use a file containing a list of 1000 integers. Let's say the contents of
>> the file look like this
>>
>> [120, 400, 500 , 20, 100 ..]
>>
>> How can I achieve that? I am trying to write a main function that takes
>> the file as an input and passes the list to my mergesort function..
>>
>> Regards
>> Awsaf Rahman
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180706/39c5bb4f/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 121, Issue 5
*****************************************