Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variant that uses no GHC-specific extensions / functions #5

Open
HeinrichApfelmus opened this issue Apr 2, 2012 · 7 comments
Open

Comments

@HeinrichApfelmus
Copy link
Owner

In an effort to make the reactive-banana library compile on UHC, I would like to include a variant of the vault package that doesn't use any GHC-specific functions. Of course, the best way to do this is to use the CPP preprocessor.

The only trouble is probably the ST monad which UHC likely doesn't have. However, I think that ST can be implemented in terms of unsafePerformIO, so it's easy to add it to the UHC libraries.

@sjoerdvisscher
Copy link

I didn't try it, but ST is in the UHC repository: https://github.com/uhc/uhc/blob/master/EHC/ehclib/base/Control/Monad/ST.hs

@HeinrichApfelmus
Copy link
Owner Author

@sjoerdvisscher Nice!

The package now uses GHC-specific extensions only when they are available.

Furthermore, I have included a module Data.Unique.Really that provides unique symbols that can survive a GHCi reload. This is important for type safety!

@HeinrichApfelmus
Copy link
Owner Author

For posterity, there is also a package

http://hackage.haskell.org/package/statethread

that implements the ST monad in terms of IORef and can be used with other compilers.

@bluescreen303
Copy link

This variant works fine with UHC.
Only thing I needed to implement was Data.Unique, for which I chose a simple increment_from_0 counter.

I did one extra tweak to vault's codebase: change Integer to Int in Data/Unique/Really.hs
Int is implemented natively in javascript, while Integer (infinite precision) needs a library. This library is not that huge, but I've managed to avoid it until now.

As javascript's Int is 53bit according to the ECMA standard (independent if the host platform is 32 or 64 bit) , this is more than enough for my needs.

But I don't expect vault to follow this, as this might be problematic on a 32bit architecture.

@HeinrichApfelmus
Copy link
Owner Author

Great!

We can make a CPP conditional for the Int if you like.

@bluescreen303
Copy link

What would the condition be?

"if UHC" doesn't seem right. I don't know if there's a macro for
UHC/JS, but even then it's probably a bit personal.
It all depends on how many unique's you expect.
Probably for 32bit archs, maxBound is already quite enough.
The only somewhat logical choice is to target UHC/JS specifically.
Just leave it for now, I have small todo/findout list, I'll add
investigating possible macros and get back to you.

On Tue, Apr 10, 2012 at 6:35 PM, Heinrich Apfelmus
reply@reply.github.com
wrote:

Great!

We can make a CPP conditional for the Int if you like.


Reply to this email directly or view it on GitHub:
#5 (comment)

@HeinrichApfelmus
Copy link
Owner Author

The only somewhat logical choice is to target UHC/JS specifically.

Yup.

It's indeed rather narrow, but I am beginning to learn that sometimes, putting workarounds in the official branch can make life easier. (Had that problem with compilation of reactive-banana on GHC 7.2)

Just leave it for now, I have small todo/findout list,

Ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants