<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">The SBV library (<a href="https://hackage.haskell.org/package/sbv" class="">https://hackage.haskell.org/package/sbv</a>) uses the ideas in Andy Gill’s Observable sharing paper (<a href="http://www.ittc.ku.edu/~andygill/papers/reifyGraph.pdf" class="">http://www.ittc.ku.edu/~andygill/papers/reifyGraph.pdf</a>) to safely observe sharing. Expressions remain pure, so long as “observation” of the sharing is done in the IO monad.<div class=""><br class=""></div><div class="">In my experience, this works really well and closely captures the application model: You want your users to program as if in a pure language, but the various backends (For SBV, this means C-compilation, SMTLib translation, Test-case generation etc.) already happens in a monadic framework, so it all works out rather nicely.</div><div class=""><br class=""></div><div class="">SBV doesn’t use Andy’s data-reify package (<a href="https://hackage.haskell.org/package/data-reify" class="">https://hackage.haskell.org/package/data-reify</a>), but that’s mostly historic. I’d definitely give that package a try. But if it doesn’t work for you for whatever reason (maybe the API doesn’t quite fit), Andy’s paper is extremely well written and you can easily use his ideas to roll your own.</div><div class=""><br class=""></div><div class="">-Levent.<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Feb 5, 2020, at 9:40 AM, Tom Schouten <<a href="mailto:tom@zwizwa.be" class="">tom@zwizwa.be</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" class="">
<div text="#000000" bgcolor="#FFFFFF" class="">
<div class="moz-cite-prefix">On 2/5/20 10:39 AM, Carter Schonwald
wrote:<br class="">
</div>
<blockquote type="cite" cite="mid:CAHYVw0wwiHwdkmMkcU=v09b6iON4HXrHq-1dzPCmX92nwfNTZw@mail.gmail.com" class="">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" class="">
<div dir="ltr" class="">Try using clash, its its own thing, and
overanalysis might be more challenging than just trying it out <br class="">
</div>
<br class="">
</blockquote><p class="">Fair point.</p><p class=""><br class="">
</p>
<blockquote type="cite" cite="mid:CAHYVw0wwiHwdkmMkcU=v09b6iON4HXrHq-1dzPCmX92nwfNTZw@mail.gmail.com" class="">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF" class=""><p class="">- There is another Functional HDL that solves this using
some unsafe reference trick to keep track of the sharing.
I believe it is CλaSH but I'm not sure. I believe you can
get away with this because the semantics is pure so in
practice doesn't cause any inconsistencies, but it really
doesn't sound like something I would do without some kind
of proof that it is actually ok. If it is ok, it would
probably make sense to abstract this in a library. Maybe
someone has done that already?<br class="">
</p>
</div>
</blockquote>
</div>
</blockquote><p class="">I was able to recover some information from my notes. I ran into
this a while ago, then decided to keep the implementation simple
and just use Monads:<br class="">
</p><p class="">A survey in Andy Gill's presentation on observable sharing:</p><p class=""><a class="moz-txt-link-freetext" href="http://www.ittc.ku.edu/~andygill/talks/20090903-hask.pdf">http://www.ittc.ku.edu/~andygill/talks/20090903-hask.pdf</a></p><p class="">Just checked the Clash website and there is a link to Christiaan
Baaij's master thesis, which has a description of the sharing
problem in Appendix C:<br class="">
</p><p class=""><a class="moz-txt-link-freetext" href="https://essay.utwente.nl/59482/1/scriptie_C_Baaij.pdf">https://essay.utwente.nl/59482/1/scriptie_C_Baaij.pdf</a></p><p class=""><br class="">
</p><p class="">I think there is probably a use for a generic library that can do
this kind of sharing recovery. Still I'm not quite happy with the
"can be unsafe in some cases" remarks and would like to learn
more. However there might be a tradeoff to use this as a
simplified interface to something that is implemented in a safe
monadic style under the hood.</p>
<br class="">
</div>
_______________________________________________<br class="">Haskell-Cafe mailing list<br class="">To (un)subscribe, modify options or view archives go to:<br class=""><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br class="">Only members subscribed via the mailman list are allowed to post.</div></blockquote></div><br class=""></div></body></html>