gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:39:47 27 4
gpt4 key购买 nike

我想做这样的事情

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com