Closed jwaldmann closed 11 years ago
simple proposal (a.k.a. Hack) for checking:
instead of case x of ...
allow to write case known x of
where
known = id
come to think of it - this known x
could be put anywhere (not just under the case) and it will just check (at runtime) that the top constructor indeed is known.
known x
https://github.com/apunktbau/co4/commit/148c8a641b3ed13161a8a8c2350254db8d11e03b provides assertKnown
and assertDefined
with the given semantics (the name known
is already taken by the allocators). Both functions require import CO4.Prelude
.
commit 534ab809214a331af820c1443e6fab762ab6f3d3 contains very simple constraint that recurses on a known list (with unknown elements)
constraint s xs = eqNat8 s ( summe xs)
summe xs = case assertKnown xs of
[] -> nat8 0
x:xs' -> plusNat8 x (summe xs')
when running it with assertions enabled, I get an exception:
ghci CO4/Test/Assert.hs
*Main> main
Start producing CNF
*** Exception: EncodedAdt.Overlapping.constantConstructorIndex: no flags
where I was expecting that it works without exception.
for debugging the space/time behaviour I want to know, for each
case
, how often it was happening on known data, and how often on unknown data. Of course "known" is better since it does not require encoding and merging.case
should ONLY be executed on known data"as long as we don't have the "modes" system, if such an annotation is present, CO4 does not generate code for matching unknown data and merging the results, but instead emits code that will throw an exception.