<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Why won't this code compile?<br><br>Michael<br><br>=======================<br><br>{- Author: Jeff Newbern<br> Maintainer: Jeff Newbern <jnewbern@nomaware.com><br> Time-stamp: <Thu Aug 14 09:53:53 2003><br> License: GPL<br>-}<br><br>{- DESCRIPTION<br><br>Example 14 - Using the IO monad<br><br>Usage: Compile the code to produce a poor replacement for<br> the standard Unix "tr" command.<br><br>Try: cat file | ./ex14 "aeiou" "X"<br> cat file | ./ex14 " " "_"<br> ./ex14 "abc"<br>-}<br><br>import Monad<br>import System<br>import IO<br>import Control.Monad.Error<br><br>-- translate char in set1 to corresponding char in set2<br>translate :: String -> String -> Char -> Char<br>translate
[] _ c = c<br>translate (x:xs) [] c = if x == c then ' ' else translate xs [] c<br>translate (x:xs) [y] c = if x == c then y else translate xs [y] c<br>translate (x:xs) (y:ys) c = if x == c then y else translate xs ys c<br><br>-- translate an entire string<br>translateString :: String -> String -> String -> String<br>translateString set1 set2 str = map (translate set1 set2) str<br><br>usage :: IOError -> IO ()<br>usage e = do putStrLn "Usage: ex14 set1 set2"<br> putStrLn "Translates characters in set1 on stdin to the corresponding"<br> putStrLn "characters from set2 and writes the translation to stdout."<br><br>-- translates stdin to stdout based on commandline
arguments<br>main :: IO ()<br>main = (do [set1,set2] <- getArgs<br> contents <- hGetContents stdin<br> putStr $ translateString set1 set2 contents)<br> `catchError` usage<br><br>-- END OF FILE<br><br>=====================================<br><br>[michael@localhost ~]$ ghc ex14.hs -o ex14<br>ex14.o: In function `rF8_info':<br>(.text+0x48): undefined reference to `mtlzm1zi1zi0zi2_ControlziMonadziError_zdf17_closure'<br>ex14.o: In function `sGp_info':<br>(.text+0x861): undefined reference to `mtlzm1zi1zi0zi2_ControlziMonadziError_zdf17_closure'<br>ex14.o: In function `sGp_info':<br>(.text+0x91d): undefined reference to `__stginit_mtlzm1zi1zi0zi2_ControlziMonadziError_'<br>ex14.o: In function `rF8_info':<br>(.text+0x50): undefined reference to
`mtlzm1zi1zi0zi2_ControlziMonadziErrorziClass_zdp1MonadError_info'<br>ex14.o: In function `sGp_info':<br>(.text+0x869): undefined reference to `mtlzm1zi1zi0zi2_ControlziMonadziErrorziClass_catchError_info'<br>ex14.o: In function `rF8_srt':<br>(.data+0x0): undefined reference to `mtlzm1zi1zi0zi2_ControlziMonadziError_zdf17_closure'<br>ex14.o: In function `Main_main_srt':<br>(.data+0x6c): undefined reference to `mtlzm1zi1zi0zi2_ControlziMonadziError_zdf17_closure'<br>collect2: ld returned 1 exit status<br>[michael@localhost ~]$ <br><br></td></tr></table><br>