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. Help me with designing my daemon, please. (Michael Litchard)
2. Re: Help me with designing my daemon, please. (David McBride)
3. Re: Help me with designing my daemon, please. (Michael Litchard)
4. rational exponents (Christopher Howard)
5. Re: Help me with designing my daemon, please. (David McBride)
6. Re: rational exponents (Brandon Allbery)
7. Re: rational exponents (Daniel Fischer)
8. Re: rational exponents (Christopher Howard)
----------------------------------------------------------------------
Message: 1
Date: Wed, 7 Sep 2011 12:01:11 -0700
From: Michael Litchard <[email protected]>
Subject: [Haskell-beginners] Help me with designing my daemon, please.
To: [email protected]
Message-ID:
<CAEzeKYon6iQ_XAdiTeSyY5S+5k7ekD0YTWZThohiS3S=zpn...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
I have a daemon I need to build, and need to work out some design
details I am having difficulty with. Here's what the design looks like
right now
When the daemon starts it creates an empty MVar and an empty TChan.
Then it listens for a usrSIG1.
when it gets one, it checks to see if the MVar is empty. If it is, it
does some stuff to fill the MVar, which is then used to pass around
state for a list of functions. These functions are always the same.
After evaluating these functions, the TChan is checked. As long as the
TChan has something in it,
it populates an MVar and the same three functions are evaluated in the
same order again.
If the MVar is full, it creates another MVar of the same type and puts
it in the TChan.
Is this a sound design? Does it prompt any questions from you? Here's
my question. If this is basically a sound design, I know I will need
use forkIO. I'm not sure where.
If this is not a sound design, please ask questions or give other
feedback so I can make changes and restore sanity.
------------------------------
Message: 2
Date: Wed, 7 Sep 2011 15:22:35 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] Help me with designing my daemon,
please.
To: Michael Litchard <[email protected]>
Cc: [email protected]
Message-ID:
<can+tr4295yx18aqw3e3kx1ec5xl9ri81s44bausadpyb7fh...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
It sounds bizarre. Why pass around an mvar in tchan, when you could
just pass a maybe around and pattern match to see if it is Nothing or
not? Also, why have forkio and tchan at all if they are only going to
operate in sequence, one at a time?
What exactly are you trying to do?
On Wed, Sep 7, 2011 at 3:01 PM, Michael Litchard <[email protected]> wrote:
> I have a daemon I need to build, and need to work out some design
> details I am having difficulty with. Here's what the design looks like
> right now
>
> When the daemon starts it creates an empty MVar and an empty TChan.
> Then it listens for a usrSIG1.
> when it gets one, it checks to see if the MVar is empty. If it is, it
> does some stuff to fill the MVar, which is then used to pass around
> state for a list of functions. These functions are always the same.
> After evaluating these functions, the TChan is checked. As long as the
> TChan has something in it,
> it populates an MVar and the same three functions are evaluated in the
> same order again.
>
> If the MVar is full, it creates another MVar of the same type and puts
> it in the TChan.
>
> Is this a sound design? Does it prompt any questions from you? Here's
> my question. If this is basically a sound design, I know I will need
> use forkIO. I'm not sure where.
> If this is not a sound design, please ask questions or give other
> feedback so I can make changes and restore sanity.
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 3
Date: Wed, 7 Sep 2011 12:31:11 -0700
From: Michael Litchard <[email protected]>
Subject: Re: [Haskell-beginners] Help me with designing my daemon,
please.
To: David McBride <[email protected]>
Cc: [email protected]
Message-ID:
<CAEzeKYrd9R2c=3hyxj77bb23npkc5b5wdkysd-bxjekjyhg...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
This is what I am trying to do.
I have tests to run and manage. I'm only running one test at a time.
When my daemon gets a signal, it will either prep a test and run it,
or queue the request. After it runs the test, I want it to check the
queue for other tests that may have been requested.
This is my first expedition into this domain. I'm trying to collect
MVars and putting tem in a TChan is the way that seemed right, but I'm
not sure at all. This is my first guess.
I thought I needed a forked thread for the eventuality that I get a
signal while my transaction is being executed.
Have I clarified or further obfuscated?
On Wed, Sep 7, 2011 at 12:22 PM, David McBride <[email protected]> wrote:
> It sounds bizarre. ?Why pass around an mvar in tchan, when you could
> just pass a maybe around and pattern match to see if it is Nothing or
> not? ?Also, why have forkio and tchan at all if they are only going to
> operate in sequence, one at a time?
>
> What exactly are you trying to do?
>
> On Wed, Sep 7, 2011 at 3:01 PM, Michael Litchard <[email protected]> wrote:
>> I have a daemon I need to build, and need to work out some design
>> details I am having difficulty with. Here's what the design looks like
>> right now
>>
>> When the daemon starts it creates an empty MVar and an empty TChan.
>> Then it listens for a usrSIG1.
>> when it gets one, it checks to see if the MVar is empty. If it is, it
>> does some stuff to fill the MVar, which is then used to pass around
>> state for a list of functions. These functions are always the same.
>> After evaluating these functions, the TChan is checked. As long as the
>> TChan has something in it,
>> it populates an MVar and the same three functions are evaluated in the
>> same order again.
>>
>> If the MVar is full, it creates another MVar of the same type and puts
>> it in the TChan.
>>
>> Is this a sound design? Does it prompt any questions from you? Here's
>> my question. If this is basically a sound design, I know I will need
>> use forkIO. I'm not sure where.
>> If this is not a sound design, please ask questions or give other
>> feedback so I can make changes and restore sanity.
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
------------------------------
Message: 4
Date: Wed, 07 Sep 2011 12:25:05 -0800
From: Christopher Howard <[email protected]>
Subject: [Haskell-beginners] rational exponents
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hi. I'm working with simple functions involving rational exponents. I
noticed that the (**) function seems to do okay with negative powers,
but that something else is needed for rational exponents:
Prelude> 2 ** (-2)
0.25
Prelude> 8 ** (1/3)
2.0
Prelude> 8 ** (2/3)
3.9999999999999996
Would there be a module meant for that sort of thing? I spent some time
in Hoogle and Hackage looking around, but nothing obvious stood out.
--
frigidcode.com
theologia.indicium.us
------------------------------
Message: 5
Date: Wed, 7 Sep 2011 16:37:01 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] Help me with designing my daemon,
please.
To: Michael Litchard <[email protected]>
Cc: [email protected]
Message-ID:
<CAN+Tr415oqR0m85RsZn8MHFHm=dEEJz5Ldgd=o6v3qt0p0e...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
I'm imagining this:
data TestInfo = {
testname :: String,
etc..
}
data TestResult = {
success :: Bool,
etc...
}
data Test = Test (TestInfo -> IO ())
type Tests = [Test]
main = do
let tests = [whatever] :: Tests
testchan <- newTChanIO :: IO (TChan TestInfo)
resultchan <- newTChanIO :: IO (TChan TestResult)
exceptionwhatever $ queuetest testchan
forkIO $ testThread (testchan,resultchan) tests
printTestResults resultChan
queuetest chan = atomically $ writeTchan (TestInfo .....)
testThread (testchan, resultchan) tests = forever $ do
newtest <- atomically $ readTChan testchan
results <- mapM tests newTest
atomically $ writeTChan resultchan results
printTestResults chan = forever $ do
x <- atomically $ readTChan chan
print x
Something like that perhaps?
On Wed, Sep 7, 2011 at 3:31 PM, Michael Litchard <[email protected]> wrote:
> This is what I am trying to do.
> I have tests to run and manage. I'm only running one test at a time.
> When my daemon gets a signal, it will either prep a test and run it,
> or queue the request. After it runs the test, I want it to check the
> queue for other tests that may have been requested.
> This is my first expedition into this domain. I'm trying to collect
> MVars and putting tem in a TChan is the way that seemed right, but I'm
> not sure at all. This is my first guess.
> I thought I needed a forked thread for the eventuality that I get a
> signal while my transaction is being executed.
> Have I clarified or further obfuscated?
>
> On Wed, Sep 7, 2011 at 12:22 PM, David McBride <[email protected]> wrote:
>> It sounds bizarre. ?Why pass around an mvar in tchan, when you could
>> just pass a maybe around and pattern match to see if it is Nothing or
>> not? ?Also, why have forkio and tchan at all if they are only going to
>> operate in sequence, one at a time?
>>
>> What exactly are you trying to do?
>>
>> On Wed, Sep 7, 2011 at 3:01 PM, Michael Litchard <[email protected]> wrote:
>>> I have a daemon I need to build, and need to work out some design
>>> details I am having difficulty with. Here's what the design looks like
>>> right now
>>>
>>> When the daemon starts it creates an empty MVar and an empty TChan.
>>> Then it listens for a usrSIG1.
>>> when it gets one, it checks to see if the MVar is empty. If it is, it
>>> does some stuff to fill the MVar, which is then used to pass around
>>> state for a list of functions. These functions are always the same.
>>> After evaluating these functions, the TChan is checked. As long as the
>>> TChan has something in it,
>>> it populates an MVar and the same three functions are evaluated in the
>>> same order again.
>>>
>>> If the MVar is full, it creates another MVar of the same type and puts
>>> it in the TChan.
>>>
>>> Is this a sound design? Does it prompt any questions from you? Here's
>>> my question. If this is basically a sound design, I know I will need
>>> use forkIO. I'm not sure where.
>>> If this is not a sound design, please ask questions or give other
>>> feedback so I can make changes and restore sanity.
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 6
Date: Wed, 7 Sep 2011 16:38:21 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] rational exponents
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID:
<cakfcl4xh59-4bsm9n6jxjhwkzh2q8hs4q9+ssr8_ukd20l2...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Wed, Sep 7, 2011 at 16:25, Christopher Howard <
[email protected]> wrote:
> Hi. I'm working with simple functions involving rational exponents. I
> noticed that the (**) function seems to do okay with negative powers, but
> that something else is needed for rational exponents:
>
Nothing else is needed; you're just seeing the inevitable failure mode of
floating point math (once you get into exponents that aren't integers, you
can't escape it). You may want to restrict printing precision.
(No, this is not a bug. No, there is no workaround that magically makes
floating point behave the way new users think it should. And no, this is
absolutely *not* Haskell-specific; the same kind of question constantly
comes up with C, C++, Perl, Java, PHP, ....)
--
brandon s allbery [email protected]
wandering unix systems administrator (available) (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110907/6ba1f3c5/attachment-0001.htm>
------------------------------
Message: 7
Date: Wed, 7 Sep 2011 23:27:19 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] rational exponents
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="utf-8"
On Wednesday 07 September 2011, 22:38:21, Brandon Allbery wrote:
> On Wed, Sep 7, 2011 at 16:25, Christopher Howard <
>
> [email protected]> wrote:
> > Hi. I'm working with simple functions involving rational exponents. I
> > noticed that the (**) function seems to do okay with negative powers,
> > but
>
> > that something else is needed for rational exponents:
> Nothing else is needed; you're just seeing the inevitable failure mode
> of floating point math (once you get into exponents that aren't
> integers, you can't escape it).
One could have an exact
(??) :: Rational -> Rational -> Maybe Rational
so that (r % s) ?? (p % q) = Just (n % d) if r^p == n^q && s^p == d^q,
Nothing otherwise (if r < 0, p even, q odd, then n has to be chosen
negative).
But when dealing with floating point numbers, you can only get the
occasional correct result by accident.
> You may want to restrict printing
> precision.
Or round to k bits.
Or write a function
rationalPower :: Floating a => a -> Rational -> a
which calculates the power e.g. by Newton's method. That would still give
incorrect results most of the time, but could produce exact results in
cases where the exact result is representable and all involved numbers are
such that no overflow occurs.
------------------------------
Message: 8
Date: Wed, 07 Sep 2011 13:32:28 -0800
From: Christopher Howard <[email protected]>
Subject: Re: [Haskell-beginners] rational exponents
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
On 09/07/2011 12:38 PM, Brandon Allbery wrote:
> On Wed, Sep 7, 2011 at 16:25, Christopher Howard
> <[email protected]
> <mailto:[email protected]>> wrote:
>
> Hi. I'm working with simple functions involving rational exponents.
> I noticed that the (**) function seems to do okay with negative
> powers, but that something else is needed for rational exponents:
>
>
> Nothing else is needed; you're just seeing the inevitable failure mode
> of floating point math (once you get into exponents that aren't
> integers, you can't escape it). You may want to restrict printing
> precision.
>
> (No, this is not a bug. No, there is no workaround that magically makes
> floating point behave the way new users think it should. And no, this
> is absolutely *not* Haskell-specific; the same kind of question
> constantly comes up with C, C++, Perl, Java, PHP, ....)
>
> --
> brandon s allbery [email protected] <mailto:[email protected]>
> wandering unix systems administrator (available) (412) 475-9364 vm/sms
>
Are there any alternative approaches that could taken? Perhaps, some
kind of Floating Ratio implementation?
Prelude Data.Ratio> 8 ** (2 % 3)
<interactive>:1:3:
No instance for (Floating (Ratio a0))
arising from a use of `**'
Possible fix: add an instance declaration for (Floating (Ratio a0))
In the expression: 8 ** (2 % 3)
In an equation for `it': it = 8 ** (2 % 3)
Or maybe an all-rational math? I'm mainly curious as my CASIO fx-115W
calculator returns a result of exactly 4 if I input 8^(2/3), but I do
not know how it arrives at the answer.
--
frigidcode.com
theologia.indicium.us
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 39, Issue 6
****************************************