[Haskell-cafe] ANN: atom-0.1.3
tomahawkins at gmail.com
Mon Jan 18 10:31:47 EST 2010
On Mon, Jan 18, 2010 at 3:19 PM, miaubiz <miaubiz at gmail.com> wrote:
> how should I feed test data into my system?
> I am having quite a bit of trouble with testing an atom with hysteresis
> because I always end up having an assertion fire before and after my test
> data is updated.
Would you explain what you are trying to do a bet more clearly?
> I have essentially the following code:
> inputs = [1, 2, 3, 4, 5]
> expected = [6, 7, 8, 9, 10]
I'm assuming you mean:
inputs <- array [1,2,3,4,5]
> output <- word16' "output"
> input <- word16' "input"
> input <== inputs !. clock
There are a few potential problems with this statement. First,
'input' in an external variable -- which is fine, just be sure nothing
is being assigned to it in the external c code. Note, if 'input' is
not referenced by external code, then 'word16 "input" 0' would be a
better variable declaration.
The second problem is a bit more serious. By using the 'clock' as an
array index, it will eventually go outside the bounds of the array.
Beware: Atom provides no array checks, such as index-out-of-bounds, or
assigning the same array location multiple times within the same
> assert "fiveIsAdded" $ (value output) ==. (expected !. clock)
Keep in mind than multiple rules will fire in one 'clock' cycle, and
assertions are checked between the execution of each rule. In this
case, the assertion will be checked before the top level rule that
contains the assignment 'input <== inputs !. clock', and before the
"addFive" rule. In both cases 'clock' will have the same value, which
will probably lead to an assertion violation.
> atom "addFive" $ period 1 $ do
> output <== (value input 5) + 5
This last statement should yield a type violation. "(value input 5)".
If your intention is to copy an array, and add 5 to each element, here
is some code they may be what you're looking for:
inputs <- array "inputs" [0, 1, 2, 3, 4]
outputs <- array "outputs" [0, 0, 0, 0, 0]
index <- word8 "index" 0
atom "copyElement" $ do
cond $ (value index) <. 5 -- Only copy elements if the index is
within the bounds of the array.
outputs ! (value index) <== inputs !. (value index) + 5
Another rule could then reset the index when new data is available to
be copied. This will then wakeup the copyElement rule to start the
copy process again.
atom "restartCopy" $ do
index <== 0
More information about the Haskell-Cafe