Mr *_*tan 1 printing recursion haskell symbols char
就像标题所说我在使用Haskell打印出符号代码及其相应符号时遇到了一些麻烦......我现在所拥有的是:
import Data.Char
import Debug.Trace
foo z | trace ("Symbolcode " ++ show z ++ " is " ++ (chr z)) False = undefined
foo z = if (z <= 128)
then foo (z+1)
else show "All done."
Run Code Online (Sandbox Code Playgroud)
......我得到这样的错误:
Couldn't match expected type `[Char]' with actual type `Char'
In the return type of a call of `chr'
In the second argument of `(++)', namely `(chr z)'
In the second argument of `(++)', namely `" is " ++ (chr z)'
Run Code Online (Sandbox Code Playgroud)
我做错了什么,是否有更简单的方法(例如不使用跟踪模块)?
您需要将Char生成的内容chr z转换为String(例如via [chr z]或return (chr z)or chr z : []等).否则,您无法在使用之前将其附加到字符串++.
foo z | trace ("Symbolcode " ++ show z ++ " is " ++ [chr z]) False = undefined
Run Code Online (Sandbox Code Playgroud)