reflex-frp / reflex-dom-semui

A reflex-dom API for Semantic UI components
https://reflex-frp.org/
BSD 3-Clause "New" or "Revised" License
22 stars 10 forks source link

CPP for foreign imports, compatibility module for GHCi #3

Closed spl closed 7 years ago

spl commented 7 years ago

The FOREIGN_IMPORT() macro makes it really easy to declare foreign import that works in GHCJS and compiles in GHC.

The compatibility module GHCJS.Compat hides the GHC stubs and cleans up the main code.

mightybyte commented 7 years ago

Oh, this is great. Thanks!

mightybyte commented 7 years ago

Hmmm, this isn't working. I'm getting this error:

src/Reflex/Dom/SemanticUI/Dropdown.hs:41:1: error:
    parse error (possibly incorrect indentation or mismatched brackets)

Not sure what's going on.

spl commented 7 years ago

Is the error where the FOREIGN_IMPORT macro is? What is your C compiler?

mightybyte commented 7 years ago

Yeah, it's the FOREIGN_IMPORT. I'm running on Mac OS X. Here's the output of gcc --version

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
spl commented 7 years ago

I think it might be a difference in the clang CPP from gcc. My guess is that it doesn't handle a multi-line macro application. I'll try it out in a bit.

spl commented 7 years ago

Well, I can't currently get it working on the Mac. Do you have GHCi working? That is, since ghcjs-dom in GHC needs gtk2hs, did you get that working on the Mac? I haven't tried GHCJS on the Mac, yet. I do most of my development in a Linux VM on the Mac.

For the moment, can you check if this solution will work? Change

FOREIGN_IMPORT(A
  B,
  C,
  D)

to

FOREIGN_IMPORT(A, B, C, D)

for all A, B, C, D.

mightybyte commented 7 years ago

I use reflex-platform to build on Mac with GHCJS. I describe how to do that in the README.

https://github.com/reflex-frp/reflex-dom-semui/blob/master/README.md

mightybyte commented 7 years ago

Ok, it looks like putting them on a single line works. I thought I tried that before and it didn't work, but I guess I was mistaken.

spl commented 7 years ago

Ok, it looks like putting them on a single line works.

Great!

spl commented 7 years ago

I use reflex-platform to build on Mac with GHCJS.

Right. But you're not using anything to build with GHC?

mightybyte commented 7 years ago

Right. But you're not using anything to build with GHC?

No. To my knowledge that can't be done until someone gets webkitgtk to build on nix in OS X.

ryantrinkle commented 7 years ago

@mightybyte I believe webkitgtk is working on current reflex-platform on OS X.

mightybyte commented 7 years ago

Oh nice. I'll have to give it a try.

mightybyte commented 7 years ago

Indeed it is. Nice!

hamishmack commented 7 years ago

I think this change is a step in the wrong direction. There was a natural place in the old code to add a GHC native implementation using JSaddle (or something else if prefered), but now it is gone.

mightybyte commented 7 years ago

@hamishmack Interesting. I'm not familiar with JSaddle. Could you provide an link to an example or perhaps snippet/pull request demonstrating how it would work in this library?

hamishmack commented 7 years ago

I'm not familiar with JSaddle.

https://github.com/ghcjs/jsaddle#jsaddle

Could you provide an link to an example or perhaps snippet/pull request demonstrating how it would work in this library?

Here is getElementById from ghcjs-dom (well from jsaddle-dom which is used by the latest ghcjs-dom when compiled with GHC)

getElementById ::
               (MonadDOM m, IsDocument self, ToJSString elementId) =>
                 self -> elementId -> m (Maybe Element)
getElementById self elementId
  = liftDOM
      (((toDocument self) ^. jsf "getElementById" [toJSVal elementId])
         >>= fromJSVal)

The JSaddle implementation of the function would look something like that. For more examples see https://github.com/ghcjs/jsaddle-dom/tree/master/src/JSDOM/Generated.

I am working on a port of reflex-dom to the latest ghcjs-dom which should be ready to try out soon. The ghcjs-dom version reflex currently uses is quite old and would not be easy to get the JSContextRef needed to run JSaddle code on GHC (but not on GHCJS). But once the port is done everything will be running in DOM (which is just IO in ghcjs-dom-jsffi and JSM in ghcjs-dom-jsaddle).