ocaml - 在 ocaml 中用换行符连接字符串

标签 ocaml

我想做这样的事情

String.concat '\n' [str1; str2 ... strn]

这样我就可以在文件中打印。但 ocaml 不允许我这样做。我能做什么?

最佳答案

String.concat "\n" [str1; str2 ... strn]

工作正常。问题是您使用了 '\n',它是字 rune 字,而不是字符串。示例:

# String.concat '\n' ["abc"; "123"];;
Error: This expression has type char but an expression was expected of type
     string
# String.concat "\n" ["abc"; "123"];;
- : string = "abc\n123"

关于ocaml - 在 ocaml 中用换行符连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9986310/

相关文章:

compiler-construction - OCaml 中 S 表达式树到抽象语法树

haskell - OCaml 中的反向状态单子(monad)

ocaml - 打印字符串的标记化

ocaml - 在模块化解析器规范中抑制 "never useful"优先警告?

ruby - 等同于 Ruby 中的 OCaml 变体

java - 使 OcaIDE 在 Mac 上的 Eclipse 中工作

recursion - OCaml - 函数调用列表中的每个元素

ocaml - 如何在 OCaml 解释器 shell 中重复最后一个命令

ocaml - 忽略 OCaml 与 OCamlbuild 的接口(interface)

string - 如何在 OCaml 中比较字符串?