javascript - 如何在 PureScript 中创建外部常量?

标签 javascript string constants purescript

我正在尝试在 PureScript 中创建一个外部常量,但它似乎没有调用该函数。

我在 PureScript 中有:

module Test where

foreign import test :: String

foreign import test2 :: String -> String

在 JavaScript 中:

"use strict";

// module Test

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

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

但它没有调用外部函数:

> 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"

是否可以创建一个外部常量?或者所有函数都至少有一个参数吗?我正在使用:

$ pulp psci --version
0.7.0.0

最佳答案

您不需要额外的功能。 String 的运行时表示只是一个字符串!

"use strict";

// module Test

exports.test = "A";
但是,

test2 是正确的。 -> 的运行时表示是一个单参数 Javascript 函数,正如您已经拥有的那样。

关于javascript - 如何在 PureScript 中创建外部常量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31840087/

相关文章:

javascript - 如何打印pdf.js文件?

json - 如何在 Go 中解码 base64 编码的 JSON

python - Pandas 字符串按可变长度位置过滤

c - 在 c 中将 const char* 转换为 char* 的问题

php - 修复未加引号的 PHP 数组键

javascript - 为什么 JSON.parse 会忽略一些数据?

javascript - 在将文本添加到文本区域之前从文本中去除 html 标签

javascript - 在 Sequelize.js 中自定义或覆盖连接

python - 可以使用字符串格式来分割字符串值吗?

创建 const 元素的 const 数组