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

Problematic serialization behavior of lists #250

Closed
snoyberg opened this issue Feb 21, 2013 · 2 comments
Closed

Problematic serialization behavior of lists #250

snoyberg opened this issue Feb 21, 2013 · 2 comments

Comments

@snoyberg
Copy link
Contributor

Consider the following contrived example, which is a (much) reduced form of a real application:

{-# LANGUAGE NoImplicitPrelude #-}
module List where

import Prelude
import FFI

data Foo = Foo

list :: ([Int] -> Fay ()) -> Fay ()
list = listFFI

listFFI :: (Automatic a -> Fay ()) -> Fay ()
listFFI = ffi "(function(f){f([])})(%1)"

foo :: (Foo -> Fay ()) -> Fay ()
foo = fooFFI

fooFFI :: (Automatic a -> Fay ()) -> Fay ()
fooFFI = ffi "(function(f){f({instance:'Foo'})})(%1)"

main :: Fay ()
main = do
    foo $ \x ->
        case x of
            Foo -> putStrLn "Foo worked"
            _ -> error "Foo: should never be reached"

    list $ \ints -> do
        print ints
        case ints of
            [] -> putStrLn "Empty list"
            _:_ -> putStrLn "Non-empty list"
            _ -> error "List: should never be reached"

I believe both listFFI and fooFFI are correct in their usage of Automatic in the type signature. However, as presented, the code error with:

Foo worked
[]

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
List: should never be reached

On the other hand, if I remove the Automatic from both locations, I get:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Foo: should never be reached

I believe the only workaround is to wrap up lists in a data constructor, but that's quite a hack.

@chrisdone
Copy link
Contributor

See #251.

@bergmark
Copy link
Member

This was fixed in 0.15.

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

3 participants