hakaru
hakaru copied to clipboard
Exposing Haskell macros in Hakaru language
There are some distributions (e.g. Cauchy, Weibull, ...) that exist in the Haskell files, but are not part of the exposed Hakaru syntax. Could these be added so that they can be accessed in Hakaru concrete syntax programs?
The simplest way to deal with this is to inline the definition of each function in each file where it's needed. That would probably get tedious very quickly, so I agree we need something better.
One solution is the import
mechanism, which has existed for a while, but has never (?) been used. There was a discussion a while back where it was concluded that the easiest to implement import
mechanism is cpp
, but for testing purposes that requires calling cpp
from Haskell, which doesn't seem too nice to me. To this end, I've (re?)enabled the import mechanism, as well as made it look in the same directory as the source file for the imports (f313a8a9f38accb610fe3c6c4f1b57ca68b95b2c). Maybe if people use it, it will have cause to become more elaborate/functional!
Another possible solution is to expose already-typed terms (i.e. those in internal syntax, defined in Haskell) to the typechecker. A very basic implementation is here: a4c6c54, 271fc8f2633f0352f7da06d465a0d67fc64aca43. Although, I'm not sure how useful this is in general. It also creates programs that don't look very nice:
$ echo "weibull(1,2)" | pretty -
(fn x2 prob:
fn x1 prob:
x0 <~ gamma(1/1, 1/1)
return x2 * x0 ** prob2real(1/ x1))
(nat2prob(1), nat2prob(2))
I think if we want the other definitions, we should make an import mechanism. @ccshan has some concerns about it being hygenic, so anybody that wants to try it should talk to him first.
On Fri, Jul 7, 2017 at 11:33 AM, yuriy0 [email protected] wrote:
The simplest way to deal with this is to inline the definition of each function in each file where it's needed. That would probably get tedious very quickly, so I agree we need something better.
One solution is the import mechanism, which has existed for a while, but has never (?) been used. There was a discussion a while back where it was concluded that the easiest to implement import mechanism is cpp, but for testing purposes that requires calling cpp from Haskell, which doesn't seem too nice to me. To this end, I've (re?)enabled the import mechanism, as well as made it look in the same directory as the source file for the imports (f313a8a https://github.com/hakaru-dev/hakaru/commit/f313a8a9f38accb610fe3c6c4f1b57ca68b95b2c). Maybe if people use it, it will have cause to become more elaborate/functional!
Another possible solution is to expose already-typed terms (i.e. those in internal syntax, defined in Haskell) to the typechecker. A very basic implementation is here: a4c6c54 https://github.com/hakaru-dev/hakaru/commit/a4c6c542e6457e716a091f93cec3f7852eab08f6, 271fc8f https://github.com/hakaru-dev/hakaru/commit/271fc8f2633f0352f7da06d465a0d67fc64aca43. Although, I'm not sure how useful this is in general. It also creates programs that don't look very nice:
$ echo "weibull(1,2)" | pretty - (fn x2 prob: fn x1 prob: x0 <~ gamma(1/1, 1/1) return x2 * x0 ** prob2real(1/ x1)) (nat2prob(1), nat2prob(2))
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hakaru-dev/hakaru/issues/96#issuecomment-313715648, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAhUYtLfiL7rq13tzAK-VFLa-Ci1oUwks5sLk_egaJpZM4OP43w .