Closed relrod closed 10 years ago
I'm running into an issue when I attempt to parse a JSON field into a 2-tuple, then access the elements of the tuple.
I've included a simplified reproducer which demonstrates the issue. It compiles perfectly fine with Fay, but throws a runtime error. :(
I'm unsure if this is a bug or if I am just doing something wrong and not getting a good error. :/
module Main where import FFI import Prelude data Foo = Foo { someString :: String , twoDoubles :: (Double, Double) } parseFoo :: String -> Fay Foo parseFoo = ffi "JSON.parse(%1)" alert :: String -> Fay () alert = ffi "alert(%1)" main :: Fay () main = do let myFoo = "{\"someString\": \"hello there\", \"twoDoubles\": [12.345, 98.765]}" parsed <- parseFoo myFoo alert (show $ twoDoubles parsed) -- [12.345, 98.765] as expected alert (show $ fst (twoDoubles parsed)) -- throws error, instead of giving 12.345 -- Uncaught TypeError: Cannot read property 'cdr' of undefined
The issues was that the instance field is missing in the JSON, #392
instance
I also added some info about the format to the wiki: https://github.com/faylang/fay/wiki/Foreign-function-interface#wiki-serialization-format
I'm running into an issue when I attempt to parse a JSON field into a 2-tuple, then access the elements of the tuple.
I've included a simplified reproducer which demonstrates the issue. It compiles perfectly fine with Fay, but throws a runtime error. :(
I'm unsure if this is a bug or if I am just doing something wrong and not getting a good error. :/