【发布时间】:2012-08-24 03:46:30
【问题描述】:
以下code:
data HelloWorld = HelloWorld;
instance Show HelloWorld where show _ = "hello world";
hello_world = "hello world"
main = putStr $ show $ (HelloWorld, hello_world)
打印:
(hello world,"hello world")
我想打印:
(hello world,hello world)
即我想要如下行为:
f "hello world" = "hello world"
f HelloWorld = "hello world"
很遗憾,show 不满足这一点,因为:
show "hello world" = "\"hello world\""
有没有像我上面描述的f 这样工作的函数?
【问题讨论】:
-
创建一个新的类型类(例如命名为
PPrint)以翻译成人类可读的Strings 是公认的好习惯。 -
@Clinton 这些答案有帮助吗?
-
f HelloWorld = "hello world"需要词法分析和大小写更改。正则表达式可能是票。
标签: haskell