abau / co4

COmplexity COncerned COnstraint COmpiler
GNU General Public License v3.0
2 stars 3 forks source link

improve tracing: check/log pattern matches on unknown/known data #20

Closed jwaldmann closed 11 years ago

jwaldmann commented 11 years ago

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.

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.

jwaldmann commented 11 years ago

simple proposal (a.k.a. Hack) for checking:

instead of case x of ... allow to write case known x of where

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.

abau commented 11 years ago

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.

jwaldmann commented 11 years ago

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.

abau commented 11 years ago

fixed by https://github.com/apunktbau/co4/commit/f82329087fc6a8f8bd4c1c6edccb86c925769984