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: Square root algorithm (PATRICK BROWNE)
2. Re: Square root algorithm (mukesh tiwari)
3. HSpec output option (Baa)
----------------------------------------------------------------------
Message: 1
Date: Mon, 11 Sep 2017 13:44:51 +0100
From: PATRICK BROWNE <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Square root algorithm
Message-ID:
<cagflrkewcx53a6ur5jobem1+d7g6rqoq0lirigeqk4_lsnt...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Why is it the sqrt0 function is so much slower than sqrt1. Does the where
clause allow intermediate values to be stored?
Regards,
Pat
sqrt0 :: Int -> Int
sqrt0 0 = 0
sqrt0 1 = 1
sqrt0 n = ((sqrt0 (n - 1)) + (n `quot` sqrt0 (n-1))) `quot` 2
-- sqrt0 25 several minutes
sqrt1 :: Int -> Int
sqrt1 n
| n == 0 = 0
| n == 1 = 1
| otherwise = div (k + ( div n k)) 2
where k = sqrt1(n-1)
-- sqrt1 25 instant
On 9 September 2017 at 05:49, KC <[email protected]> wrote:
> One approach
>
> One function to compute the next iterate
>
> Another function to call the computation function until results are within
> some tolerance
>
> It's usually presented as separation of control and computation đ
>
> --
> Sent from an expensive device which will be obsolete in a few months
> Casey
>
> On Sep 3, 2017 1:23 AM, "mike h" <[email protected]> wrote:
>
>> Hi,
>>
>> To help me in learning Haskell I started blogging about some of the
>> things Iâve looked at.
>> One such topic was calculating square roots âby handâ and then deriving a
>> Haskell algorithm.
>> I wrote about the well known technique here
>> http://gitcommit.co.uk/2017/08/25/the-root-of-the-problem-part-1/
>>
>> and it it is really quite a simple method.
>>
>> The second part of the post will be an implementation in Haskell.
>>
>> I then tried implementing it and got something that works but really its
>> not very pleasant to look at! And its something I donât want to post! Some
>> parts are fine but I think I locked myself into the notion that it had to
>> be using State and really the end result is pretty poor.
>>
>> I know this i perhaps a âbig askâ but Iâd really appreciate any
>> suggestions, solutions, hints etc. I will of course give full attribution.
>>
>> Iâve created a gist of the code here
>> https://gist.github.com/banditpig
>>
>> Many Thanks
>>
>> Mike
>>
>> _______________________________________________
>> 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
>
>
--
This email originated from DIT. If you received this email in error, please
delete it from your system. Please note that if you are not the named
addressee, disclosing, copying, distributing or taking any action based on
the contents of this email or attachments is prohibited. www.dit.ie
Is Ăł ITBĂC a thĂĄinig an rĂomhphost seo. MĂĄ fuair tĂș an rĂomhphost seo trĂ
earrĂĄid, scrios de do chĂłras Ă© le do thoil. Tabhair ar aird, mura tĂș an
seolaĂ ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chĂłipeĂĄil, aon
dĂĄileadh nĂł ar aon ghnĂomh a dhĂ©anfar bunaithe ar an ĂĄbhar atĂĄ sa
rĂomhphost nĂł sna hiatĂĄin seo. www.dit.ie
TĂĄ ITBĂC ag aistriĂș go GrĂĄinseach GhormĂĄin â DIT is on the move to
Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20170911/856e95ee/attachment-0001.html>
------------------------------
Message: 2
Date: Tue, 12 Sep 2017 10:36:58 +1000
From: mukesh tiwari <[email protected]>
To: [email protected], The Haskell-Beginners Mailing List -
Discussion of primarily beginner-level topics related to Haskell
<[email protected]>
Subject: Re: [Haskell-beginners] Square root algorithm
Message-ID:
<cafhzve_shodkqri8o0tgk4rsqkbqk9yd2---qwaoygy9vvf...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi Patrick,
On Mon, Sep 11, 2017 at 10:44 PM, PATRICK BROWNE <[email protected]>
wrote:
> Why is it the sqrt0 function is so much slower than sqrt1. Does the where
> clause allow intermediate values to be stored?
> Regards,
> Pat
> sqrt0 :: Int -> Int
> sqrt0 0 = 0
> sqrt0 1 = 1
> sqrt0 n = ((sqrt0 (n - 1)) + (n `quot` sqrt0 (n-1))) `quot` 2
> -- sqrt0 25 several minutes
>
In sqrt0, each function call with n > 1 creates two more function call, and
this creates exponential blow up (factor of 2). You can make your code it
faster by storing the intermediate result
sqrt0 :: Int -> Int
sqrt0 0 = 0
sqrt0 1 = 1
sqrt0 n = let k = sqrt0 (n - 1) in (k + (n `quot` k)) `quot` 2
This code is not blowing exponentially because of you storing intermediate
result leading to faster computation.
sqrt1 :: Int -> Int
> sqrt1 n
> | n == 0 = 0
> | n == 1 = 1
> | otherwise = div (k + ( div n k)) 2
> where k = sqrt1(n-1)
> -- sqrt1 25 instant
>
>
> On 9 September 2017 at 05:49, KC <[email protected]> wrote:
>
>> One approach
>>
>> One function to compute the next iterate
>>
>> Another function to call the computation function until results are
>> within some tolerance
>>
>> It's usually presented as separation of control and computation đ
>>
>> --
>> Sent from an expensive device which will be obsolete in a few months
>> Casey
>>
>> On Sep 3, 2017 1:23 AM, "mike h" <[email protected]> wrote:
>>
>>> Hi,
>>>
>>> To help me in learning Haskell I started blogging about some of the
>>> things Iâve looked at.
>>> One such topic was calculating square roots âby handâ and then deriving
>>> a Haskell algorithm.
>>> I wrote about the well known technique here
>>> http://gitcommit.co.uk/2017/08/25/the-root-of-the-problem-part-1/
>>>
>>> and it it is really quite a simple method.
>>>
>>> The second part of the post will be an implementation in Haskell.
>>>
>>> I then tried implementing it and got something that works but really
>>> its not very pleasant to look at! And its something I donât want to post!
>>> Some parts are fine but I think I locked myself into the notion that it had
>>> to be using State and really the end result is pretty poor.
>>>
>>> I know this i perhaps a âbig askâ but Iâd really appreciate any
>>> suggestions, solutions, hints etc. I will of course give full attribution.
>>>
>>> Iâve created a gist of the code here
>>> https://gist.github.com/banditpig
>>>
>>> Many Thanks
>>>
>>> Mike
>>>
>>> _______________________________________________
>>> 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
>>
>>
>
> This email originated from DIT. If you received this email in error,
> please delete it from your system. Please note that if you are not the
> named addressee, disclosing, copying, distributing or taking any action
> based on the contents of this email or attachments is prohibited.
> www.dit.ie
>
> Is Ăł ITBĂC a thĂĄinig an rĂomhphost seo. MĂĄ fuair tĂș an rĂomhphost seo trĂ
> earrĂĄid, scrios de do chĂłras Ă© le do thoil. Tabhair ar aird, mura tĂș an
> seolaĂ ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chĂłipeĂĄil, aon
> dĂĄileadh nĂł ar aon ghnĂomh a dhĂ©anfar bunaithe ar an ĂĄbhar atĂĄ sa
> rĂomhphost nĂł sna hiatĂĄin seo. www.dit.ie
>
> TĂĄ ITBĂC ag aistriĂș go GrĂĄinseach GhormĂĄin â DIT is on the move to
> Grangegorman <http://www.dit.ie/grangegorman>
>
> _______________________________________________
> 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/20170912/246d93a7/attachment-0001.html>
------------------------------
Message: 3
Date: Tue, 12 Sep 2017 11:06:55 +0300
From: Baa <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] HSpec output option
Message-ID: <20170912110655.1cea1a86@Pavel>
Content-Type: text/plain; charset=US-ASCII
Hello, Dear List!
I have tests: I'm using HSpec (and QuickCheck too). And I have tests
like this:
describe "Something" $ do
it "something is correct" $ do
...blah-blah...
it "any string is correct" $ property $
\s -> all (=='*') (Something s) -- it's for example only!!!
so something like unit-test and property checks in one SomethingSpec.hs.
I'm running them with this Makefile:
.PHONY: test fast-test
fast-test:
stack exec runhaskell -- -isrc -itest test/Spec.hs
test:
stack test
and in Spec.hs I have:
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
That's all. So, when I find failed test, I get a trace like this:
...
Failures:
test/SomethingSpec.hs:172:
1) BlahBlah.superFunc any string is correct:
result Gave up after 48 tests
...etc...
So, my question is: when QuichCheck runs my property test, it passes
argument to property's lambda. And on 48th test attempt with some
concreate argument value my check fails. How can I get detailed output
from such test environment, to see what concreate arguments lead to
failure? To see something (or similar/or more detailed even):
Failed with arguments: s = ""
Is it possible (I run them with stack and with runhaskell too) ?
===
Best regards, Paul
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 111, Issue 7
*****************************************