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

String conversion in polymorphic ffi functions #244

Closed
andrey013 opened this issue Feb 15, 2013 · 2 comments
Closed

String conversion in polymorphic ffi functions #244

andrey013 opened this issue Feb 15, 2013 · 2 comments

Comments

@andrey013
Copy link

I would like logged strings to be the same.

{-# LANGUAGE NoImplicitPrelude #-}
module String where

import Prelude
import FFI

print' :: String -> Fay ()
print' = ffi "console.log(\"\"+%1)"

print'' :: a -> Fay ()
print'' = ffi "console.log(\"\"+%1)"

print''' :: Automatic a -> Fay ()
print''' = ffi "console.log(\"\"+%1)"

main :: Fay ()
main = do
    let s = "hello"
    print' s    -- hello
    print'' s   -- [object Object]
    print''' s  -- [object Object]

#185 may be relevant since:

print :: Automatic a -> Fay ()
print = ffi "(function(x) { if (console && console.log) console.log(x) })(%1)"

putStrLn :: String -> Fay ()
putStrLn = ffi "(function(x) { if (console && console.log) console.log(x) })(%1)"
@bergmark
Copy link
Member

bergmark commented Jul 1, 2013

A little sad but I think this won't work. If we run across [] or null (an empty fay list) there is no way to know if the value should be treated as String or [a].

@bergmark
Copy link
Member

I'll close this. Don't do polymorphic serialiations on [Char] . Use Fay.Text instead.

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

2 participants