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

JSString support #9

Open
dmjio opened this issue Nov 2, 2016 · 6 comments
Open

JSString support #9

dmjio opened this issue Nov 2, 2016 · 6 comments

Comments

@dmjio
Copy link

dmjio commented Nov 2, 2016

@soenkehahn, hello :)

What do you think about adding JSString support?

-- from JSString

#ifdef __GHCJS__
import Data.JSString 
import Data.JSString.Text
#endif

....

#ifdef __GHCJS__
instance ConvertibleStrings JSString JSString where
    convertString = id

instance ConvertibleStrings JSString String where
    convertString = unpack'

instance ConvertibleStrings JSString StrictByteString where
    convertString = Data.Text.Encoding.encodeUtf8 . textFromJSString

instance ConvertibleStrings JSString LazyByteString where
    convertString = Data.Text.Lazy.Encoding.encodeUtf8 . lazyTextFromJSString

instance ConvertibleStrings JSString StrictText where
    convertString = textFromJSString

instance ConvertibleStrings JSString LazyText where
    convertString = lazyTextFromJSString
#endif
@soenkehahn
Copy link
Owner

Yeah, I'd be fine with merging a PR.

I wonder whether this should better be in a separate module Data.String.Conversions.GHCJS which -- through CPP -- would be an empty module on ghc.

@dmjio
Copy link
Author

dmjio commented Nov 2, 2016

Sounds good, was a bit worried about orphans if there was a separate module (unless the class definition was copied as well). Might be able to skip CPP altogether if cabal file was arranged like so:

library
   if impl(ghcjs)
      hs-source-dirs: ghcjs-src
      exposed-modules: Data.String.Conversions
      build-depends: ghcjs-base
   else
     hs-source-dirs: src
     exposed-modules: Data.String.Conversions
     build-depends: text, bytestring

Unsure if hpack allows for impl(ghcjs) syntax though

@dmjio
Copy link
Author

dmjio commented Nov 2, 2016

It seems like hpack supports conditionals

when:
  - condition: flag(fast)
    then:
      ghc-options: -O2
    else:
      ghc-options: -O0

@soenkehahn
Copy link
Owner

I think I would still prefer CPP over impl(ghcjs).

@dmjio
Copy link
Author

dmjio commented Nov 2, 2016

Ok, that's fine too. So then should we do the single module approach, but
#ifdef on imports and instances?

On Wed, Nov 2, 2016 at 1:57 PM, Sönke Hahn [email protected] wrote:

I think I would still prefer CPP over impl(ghcjs).


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA1bPM2xQogLbgYi5309JXpGOk1SWIulks5q6N0ggaJpZM4Km5I6
.

Cell: 1.630.740.8204

@soenkehahn
Copy link
Owner

Yes, please.

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

2 participants