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

Type aliases are not resolved in FFI conversions #185

Open
bergmark opened this issue Dec 13, 2012 · 5 comments
Open

Type aliases are not resolved in FFI conversions #185

bergmark opened this issue Dec 13, 2012 · 5 comments

Comments

@bergmark
Copy link
Member

Reported by cmccann and lucca on irc, I reproduced it like this:

import Language.Fay.FFI
import Language.Fay.Prelude

type S = String

data R = R S
instance Foreign R

data Q = Q String
instance Foreign Q

main :: Fay ()
main = do
  putStrLn ("hej" :: S)
  putStrLn ("hej" :: String)
  print $ R "hej"
  print $ Q "hej"

=>

hej
hej
{ instance: 'R',
  slot1: { car: 'h', cdr: { car: 'e', cdr: [Object] } } }
{ instance: 'Q', slot1: 'hej' }

So if the ffi signature is concrete as in putStrLn the encoding works, but not for the generic print.

@bergmark
Copy link
Member Author

And fayToJs and jsToFay looks like this:

  if (_obj instanceof $_Main$R) {
    var obj_ = {"instance": "R"};
    var obj_slot1 = Fay$$fayToJs(["user","S",[]],_(_obj.slot1));
    if (undefined !== obj_slot1) {
      obj_['slot1'] = obj_slot1;
    }
    return obj_;
  }


  if (obj["instance"] === "Q") {
    return new $_Main$Q(Fay$$jsToFay(["string"],obj["slot1"]));
  }
  if (obj["instance"] === "R") {
    return new $_Main$R(Fay$$jsToFay(["user","S",[]],obj["slot1"]));
  }

Can we fix this with a Map Name Name for type aliases?

@chrisdone
Copy link
Contributor

Yeah, I guess we can do that. There'll need to be a little bit of Type -> Type resolving, too (e.g. type Foo a = String and then Foo IntString). I mentioned this on IRC months ago but forgot to make a ticket.

@bergmark
Copy link
Member Author

Does Automatic solve this (temporarily)? It might be a good idea to give a warning until this is implemented properly.

@jameshfisher
Copy link

I just hit this; I don't think Automatic does solve it, if I'm using it correctly:

module Aliases where

import Prelude
import FFI

type Name = String

alert :: Automatic Name -> Fay ()
alert = ffi "window['alert'](%1)"

main :: Fay ()
main = alert "James"

alerts "[Object object]". Same for without Automatic.

@jazmit
Copy link

jazmit commented May 10, 2013

👍 encountered this issue.. also tried using Automatic without success. Stripping type aliases out of my code has solved this temporarily, but it's not a nice solution.

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

No branches or pull requests

4 participants