[Haskell-cafe] ANN: atom-0.1.3

Tom Hawkins tomahawkins at gmail.com
Sun Jan 17 16:56:53 EST 2010


On Sun, Jan 17, 2010 at 1:16 PM, miaubiz <miaubiz at gmail.com> wrote:
>
> I am trying to generate a square wave.  Here's the code:
>
>    square <- bool "square" False
>
>    period 2 $ atom "square high" $ phase 0 $ do
>        square <== true
>        assert "square is low" $ not_ $ value square
>
>    period 2 $ atom "square low" $ phase 1 $ do
>        square <== false
>        assert "square is high" $ value square
>
>
> The tests fail every cycle because after each rule one of them is wrong.

If you are using the latest version of Atom, asserts are checked
between the execution of every rule.  The way you've coded it, it may
appear as if the assertions are checked along with the associated
rules, but this is not the case.  And not only are the assertions not
checked with the rules, they don't follow the period or phase
constraints either.  So what you have is essentially 2 assertions that
are being checked at every time instance and between every atom state
update.

>
> What would be the right way to formulate this code? Use cond on the rules?
>
>    period 2 $ atom "square high" $ phase 0 $ do
>        cond $ not_ $ value square
>        square <== true
>        cover "lowSquare" true
>        assert "square is low" $ not_ $ value square
>
>    period 2 $ atom "square low" $ phase 1 $ do
>        cond $ value square
>        square <== false
>        cover "highSquare" true
>        assert "square is high" $ value square
>
>

Yes, guard conditions would help.  Guards are hierarchical; they apply
to all the sub Atom rules and assertions.  As such ...

  cond $ not_ $ value square
  assert "squareIsLow" $ not_ $ value square

.. is a redundant because the guard condition is the same as the
assertion.  The guard will only allow the assertion to be checked if
'square' is false, and if it does, the assertion is guaranteed to
pass.

An easier way to write a square wave is this...

square <- bool "square" False

period 2 $ atom "toggle" $ do
  square <== not_ (value square)


> as an aside, in Unit.hs:
>         covered = [ words line !! 1 | line <- lines log, isPrefixOf
> "covered:" line ]
>
> because covered is the second word of the line from the log, the name of
> cover must be a single word. assertions and atoms can contain spaces as far
> as I can tell.

No, they really shouldn't.  I've been meaning to add some checks to
enforce some naming rules, but haven't gotten around to it.

I hope this helps.

-Tom

>
> br, miau
> --
> View this message in context: http://old.nabble.com/ANN%3A-atom-0.1.3-tp26624813p27198213.html
> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list