Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/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: Data.Stream interleave implementation question (Bryan Brady)
2. Re: Data.Stream interleave implementation question (Bryan Brady)
3. Re: Data.Stream interleave implementation question (Kim-Ee Yeoh)
4. Re: Data.Stream interleave implementation question (Brent Yorgey)
----------------------------------------------------------------------
Message: 1
Date: Wed, 12 Feb 2014 07:49:04 -0500
From: Bryan Brady <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Data.Stream interleave implementation
question
Message-ID:
<CAC2KVSR4F0EtjF3v+7heH=j3xq-SOJBjmvMoZ4+SU_Fed9Bu=a...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Thanks Isaac! It never crossed my mind that the problem was on the left
hand side.
On Wed, Feb 12, 2014 at 3:36 AM, Isaac Dupree <
[email protected]> wrote:
> [...]
> In this situation, if interleaveStreams evaluates its second argument
> before returning any work, it will never be able to return. Happily, the
> outer Cons of the result does not depend on the second argument. I can fix
> the issue just by making the second argument be pattern-matched lazily
> (with ~, i.e. only as soon as any uses of the argument in the function are
> evaluated):
>
interleaveStreams (Cons a as) ~(Cons b bs) = Cons a (Cons b
> (interleaveStreams as bs))
>
>
> So that's what the ~ does... :)
I'm not sure whether there's a practical difference between these and
> Data.Stream's definition. Actually, I think they turn out to do exactly
> the same thing...
>
Yes, they do. I used the solution in Data.Stream to fix mine, though I
didn't recognize the true source of the problem until you pointed it out.
Thanks again!
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140212/86de6862/attachment-0001.html>
------------------------------
Message: 2
Date: Wed, 12 Feb 2014 08:05:55 -0500
From: Bryan Brady <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Data.Stream interleave implementation
question
Message-ID:
<CAC2KVSRY6EsfGmKdn3uOk1aThsX3tfFKCsDSH0zDhVsB2fXr=g...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Wed, Feb 12, 2014 at 3:10 AM, Kim-Ee Yeoh <[email protected]> wrote:
> I'd hazard to say that it's probably not the solution the author had in
> mind, so bonus points for novelty!
>
What solution do you think the author had in mind? He did hint to use
define and use interleaveStreams and to avoid checking divisibility
testing.
> How would you prove it correct though?
>
I haven't attempted this yet, but if I were to, I'd go for an inductive
proof. If you list the solution along with the numbers they correspond to
(divide), you get:
1 2 3 4 5 6 7 8 9 10...
0 1 0 2 0 1 0 3 0 1...
If you drop all the numbers corresponding to a 0 in the ruler function:
2 4 6 8 10...
1 2 1 3 1 ...
then drop the numbers corresponding to a 1 in the ruler function:
4 6 ...
2 3 ...
At each level, you drop every other number, and the first number of each
successive level is 1 greater than the previous level. Formalize that a bit
and you got a proof.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140212/263925bf/attachment-0001.html>
------------------------------
Message: 3
Date: Wed, 12 Feb 2014 21:03:52 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Data.Stream interleave implementation
question
Message-ID:
<capy+zdtlfyum5qry16qqnyrmhmfqaenaaj_6i82l7joxb_q...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Wed, Feb 12, 2014 at 8:05 PM, Bryan Brady <[email protected]> wrote:
> What solution do you think the author had in mind? He did hint to use
> define and use interleaveStreams and to avoid checking divisibility
> testing.
Recall the famous haskell fibonacci:
fib = 0 : 1 : some_function_of fib
Mathematically speaking, what fractal property does the ruler sequence
observe that you could similarly exploit?
As for your solution, I don't doubt for a minute it's correct (I probably
could have worded what I said better). The hope is that a proof would be
interesting/delightful in that ineffable math-y way.
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140212/263de823/attachment-0001.html>
------------------------------
Message: 4
Date: Wed, 12 Feb 2014 12:19:39 -0500
From: Brent Yorgey <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Data.Stream interleave implementation
question
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Wed, Feb 12, 2014 at 03:10:21PM +0700, Kim-Ee Yeoh wrote:
> On Wed, Feb 12, 2014 at 11:23 AM, Bryan Brady <[email protected]> wrote:
>
> > ruler :: Stream Integer
> > ruler = foldr1 interleaveStreams (map streamRepeat [0..])
> >
>
> This is an interesting solution.
>
> I'd hazard to say that it's probably not the solution the author had in
> mind, so bonus points for novelty!
You're right that it's not the exact solution I had in mind, but I
like it! I had in mind a more directly recursive version of ruler; I
think proving the two solutions equivalent should not be too hard.
-Brent
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 68, Issue 11
*****************************************