2
votes

I'm trying to create a foreign constant in PureScript but it doesn't seem to call the function.

I have in PureScript:

module Test where

foreign import test :: String

foreign import test2 :: String -> String

and in JavaScript:

"use strict";

// module Test

exports.test = function() {
    return "A";
};

exports.test2 = function(x) {
    return x;
};

But it doesn't call the foreign function:

> import Prelude
> :t test
Prim.String
> :t test2
Prim.String -> Prim.String
> test
undefined

> test2 "test"
"test"
> test ++ "A"
"function () {\n    return \"A\";\n}A"

Is it possible to create a foreign constant? Or are all functions expected to have at least one parameter? I'm using:

$ pulp psci --version
0.7.0.0
1

1 Answers

3
votes

You don't need the extra functions. The runtime representation of String is just a string!

"use strict";

// module Test

exports.test = "A";

test2 is correct, however. The runtime representation of -> is a one-argument Javascript function, as you already have.