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. Re:  Streams (mike h)


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

Message: 1
Date: Thu, 27 Jul 2017 13:29:00 +0100
From: mike h <mike_k_hough...@yahoo.co.uk>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Streams
Message-ID: <852910cf-cf85-46cf-adbe-294cb9a99...@yahoo.co.uk>
Content-Type: text/plain; charset=utf-8

Thanks Francesco - I’ll follow up the link.
M
> On 27 Jul 2017, at 11:08, Francesco Ariis <fa...@ariis.it> wrote:
> 
> On Thu, Jul 27, 2017 at 09:33:33AM +0100, mike h wrote:
>> What I'd like to do is take one item at a time from the stream. My first
>> shot was 
>> 
>> next :: (Stream a) -> (Stream a, a)
>> 
>> but that means I need to keep a ref to the stream that is returned in the 
>> tuple which makes for messy code
>> for subsequent calls to next. I sense that the State monad needs to be 
>> involved but I'm not sure exactly how as 
>> my experiments with State still required I keep a ref to the 'new' stream. 
>> Conceptually I see this as a 'global' state
>> and  next is just
>> 
>> next :: a
>> 
>> but that's 30 years of imperative programming speaking and is, I think,
>> wrong! 
> 
> Hello Mike,
> 
>    I see nothing wrong with a State monad (you signature looks really like
> the one inside a State monad, after all)
> 
>    next  :: Stream a -> (a, Stream a)
>    next' :: s        -> (a, s       )
> 
> Many many many other ways of dealing elegantly with streams have been
> proposed; check for example this article [1], which starts exactly
> from your example, e.g.
> 
>    data Stream b = SCons (b, Stream b)
> 
> And then, if you are sold to the idea, exploring the various libraries
> on hackage is the other half of the fun :P
> -F
> 
> [1] https://blog.jle.im/entry/intro-to-machines-arrows-part-1-stream-and
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 109, Issue 21
******************************************

Reply via email to