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

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

Comments

Projects
None yet
3 participants
Owner

HeinrichApfelmus commented Apr 2, 2012

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.

Owner

HeinrichApfelmus commented Apr 4, 2012

@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!

Owner

HeinrichApfelmus commented Apr 8, 2012

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.

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.

Owner

HeinrichApfelmus commented Apr 10, 2012

Great!

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

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)

Owner

HeinrichApfelmus commented Apr 11, 2012

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