Like the title says I’m having some trouble printing out symbol codes and their corresponding symbols using Haskell…what I have at the moment is this:
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."
…and I get an error like this:
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)'
What am I doing wrong and is there an easier way of doing this (for example without using the trace module)?
It is a bad idea to use
tracefor anything other than debugging, because the execution order is unreliable.If you want to do something for all integers in a range, start by making the list
[0 .. 127]of integers you want to process. To output some text, you should use an IO action such asputStrLn. Unliketrace,putStrLnwill always execute when it is supposed to. Map this IO action over your list to print all the characters.