Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  How does forever works ? (Olivier Revollat)
   2. Re:  How does forever works ? (Francesco Ariis)
   3. Re:  How does forever works ? (Olivier Revollat)
   4.  Storing the time difference between two  Monotonic time
      results (Awsaf Rahman)


----------------------------------------------------------------------

Message: 1
Date: Mon, 9 Jul 2018 13:31:07 +0200
From: Olivier Revollat <revol...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] How does forever works ?
Message-ID:
        <ca+nxgrunlkv+ev9ymmrpmjvtmt+tyo35qsx-5k9djzukwtk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

>From what I understand, this code

main = forever $ do
  putStrLn "OK !"

is equivalent to this one :

main = do
  putStrLn "OK !"
  main

In the second case, it's a simple recursion, so far so good ... but when I
look at the implementation of "forever" i can't wrap my head around :

http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#forever

forever 
<http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#forever>
a 
<http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#local-6989586621679327090>
  = let a' 
<http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#local-6989586621679327091>
= a 
<http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#local-6989586621679327090>
*> 
<http://hackage.haskell.org/package/base-4.11.1.0/docs/src/GHC.Base.html#%2A%3E>
a' 
<http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#local-6989586621679327091>
in a' 
<http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#local-6989586621679327091>

How does this works ? How does this make an infinite loop ?

I understand that *> discard his right argument but it doesn't help me
understand how forever implement an infinite loop ...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20180709/b9fbb3d7/attachment-0001.html>

------------------------------

Message: 2
Date: Mon, 9 Jul 2018 13:54:29 +0200
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] How does forever works ?
Message-ID: <20180709115429.q3qyb7g3prgrv...@x60s.casa>
Content-Type: text/plain; charset=us-ascii

Hello Olivier,

On Mon, Jul 09, 2018 at 01:31:07PM +0200, Olivier Revollat wrote:
> In the second case, it's a simple recursion, so far so good ... but when I
> look at the implementation of "forever" i can't wrap my head around :
> 
> http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#forever

    forever a   = let a' = a *> a' in a'

`*>` is the same as `>>` (if you have ever met `>>`), with the difference
that the latter works on monads only. In do notation, we could write

    forever :: Monad m => m a -> m b
    forever a = let a' = do a
                            a' in
                do a'

Which should be easier to get: we `do` a'; a' is nothing but a and a',
so we do a and then a', which is nothing but a and a', etc.

Does this explanation feel right?

As soon as you can, familiarise yourself what the do notation desugars to:
in my opinion plain operators are clearer
-F


------------------------------

Message: 3
Date: Mon, 9 Jul 2018 13:58:56 +0200
From: Olivier Revollat <revol...@gmail.com>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] How does forever works ?
Message-ID:
        <CA+nXgrU1CeaOw6T=xbCZCsD7u-VcBaFaoYUk=mxq0sarm1c...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hey I think it's a bit clearer now .... need to meditate on this :) Thanks !

Le lun. 9 juil. 2018 à 13:55, Francesco Ariis <fa...@ariis.it> a écrit :

> Hello Olivier,
>
> On Mon, Jul 09, 2018 at 01:31:07PM +0200, Olivier Revollat wrote:
> > In the second case, it's a simple recursion, so far so good ... but when
> I
> > look at the implementation of "forever" i can't wrap my head around :
> >
> >
> http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#forever
>
>     forever a   = let a' = a *> a' in a'
>
> `*>` is the same as `>>` (if you have ever met `>>`), with the difference
> that the latter works on monads only. In do notation, we could write
>
>     forever :: Monad m => m a -> m b
>     forever a = let a' = do a
>                             a' in
>                 do a'
>
> Which should be easier to get: we `do` a'; a' is nothing but a and a',
> so we do a and then a', which is nothing but a and a', etc.
>
> Does this explanation feel right?
>
> As soon as you can, familiarise yourself what the do notation desugars to:
> in my opinion plain operators are clearer
> -F
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20180709/82d37be8/attachment-0001.html>

------------------------------

Message: 4
Date: Mon, 9 Jul 2018 14:30:04 +0200
From: Awsaf Rahman <awsafrahman1...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Storing the time difference between two
        Monotonic time results
Message-ID:
        <CAOH+Qtfj+qhxrZgsr2vhad2vmC1yu1A=mdgzypqw127tesv...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hello,

I am trying to time a function I have written in haskell using the clock
package in the following way:

*start <- getTime Monotonic*
*evaluate(something)*
*end <- getTime Monotonic*
*fprint (timeSpecs % "\n") start end*


Now what I want is to store the time difference between *start* and *end. *Is
there a way I can do that?

Regards
Awsaf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20180709/d0802dca/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 121, Issue 6
*****************************************

Reply via email to