haskell - 我们如何在 Haskell 中将 boolean 值转换为字符串

标签 haskell boolean

我是 Haskell 的初学者。我试图将一个字符串添加到列表中,这个字符串应该包含 "TRUE""FALSE"视情况而定。

type Output = [String]
type T = Bool 

f :: T -> [String]

我试图使用 printf在这里,但我不知道 bool 类型的符号(如 %d 表示 int)。有什么好的方法可以做到这一点吗?谢谢!

最佳答案

一个简单的 if 表达式怎么样?

if condition then "TRUE" else "FALSE"

或者,如果你不关心大写,你可以使用 show在 boolean 值上。

关于haskell - 我们如何在 Haskell 中将 boolean 值转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37019716/

相关文章:

powershell - Powershell等同于Linux true命令

java - 制作一个在字符串中查找小写字母的方法

javascript - 检查 Typescript/Javascript 中与 "true"、 "false"和 "undefined"相关的 boolean 值

haskell - 数字类型的相等性如何工作?

haskell - 如何使用 Scott 编码表示嵌套类型?

haskell - 在 attoparsec 中实现skipWhile1

haskell - 在 Haskell map 上求和

haskell - 非无点风格要慢得多

Javascript/Jquery boolean 帮助 : Hiding/Showing Divs

Java - 我需要在主方法内使用变量 boolean 值,在外部但在同一个类内初始化