Skip to content

show returns undefined inside FFI/JS #4564

Description

@Hi-Angel

Description

Following official documentation, to call show upon a data value inside JS I just need to do that, it should Just Work™.

But for some reason show returns undefined. More over, if I do spago bundle-app and look at the resulting index.js, I don't even see the string for the Show instance to produce, so if there's some odd trick required, it's impossible to derive from the output.

This came up as part of forum discussion.

To Reproduce

  1. Create src/Main.purs as:

    module Main where
    
    import Prelude
    
    import Effect (Effect)
    
    data Foo = Foo
    instance fooShow :: Show Foo where
      show Foo = "Foo"
    
    -- | re-export of `show`
    show_ ::  a. Show a => a -> String
    show_ = show
    
    foreign import printFoo :: Foo -> Effect Unit
    
    main :: Effect Unit
    main = printFoo Foo -- same as `log $ show Foo`

    and src/Main.js as:

    import { show_ } from '../Main/index.js';
    
    export const printFoo = function(foo) {
        return function () {
            console.log(show_(foo));
        };
    };
  2. Execute spago run

Expected behavior

It should output Foo, not undefined

PureScript version

0.15.15

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions