How do I create a foreign constant in PureScript?

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

I have 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 external 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 should all functions have at least one parameter? I use:

$ pulp psci --version
0.7.0.0

      

+3


source to share


1 answer


You don't need additional features. The runtime view String

is just a string!

"use strict";

// module Test

exports.test = "A";

      



test2

is correct. The runtime ->

view is a Javascript function with one argument, as you already know.

+4


source







All Articles