[Haskell-cafe] Example code won't compile
michael rice
nowgate at yahoo.com
Fri May 15 19:17:28 EDT 2009
Why won't this code compile?
Michael
=======================
{- Author: Jeff Newbern
Maintainer: Jeff Newbern <jnewbern at nomaware.com>
Time-stamp: <Thu Aug 14 09:53:53 2003>
License: GPL
-}
{- DESCRIPTION
Example 14 - Using the IO monad
Usage: Compile the code to produce a poor replacement for
the standard Unix "tr" command.
Try: cat file | ./ex14 "aeiou" "X"
cat file | ./ex14 " " "_"
./ex14 "abc"
-}
import Monad
import System
import IO
import Control.Monad.Error
-- translate char in set1 to corresponding char in set2
translate :: String -> String -> Char -> Char
translate [] _ c = c
translate (x:xs) [] c = if x == c then ' ' else translate xs [] c
translate (x:xs) [y] c = if x == c then y else translate xs [y] c
translate (x:xs) (y:ys) c = if x == c then y else translate xs ys c
-- translate an entire string
translateString :: String -> String -> String -> String
translateString set1 set2 str = map (translate set1 set2) str
usage :: IOError -> IO ()
usage e = do putStrLn "Usage: ex14 set1 set2"
putStrLn "Translates characters in set1 on stdin to the corresponding"
putStrLn "characters from set2 and writes the translation to stdout."
-- translates stdin to stdout based on commandline arguments
main :: IO ()
main = (do [set1,set2] <- getArgs
contents <- hGetContents stdin
putStr $ translateString set1 set2 contents)
`catchError` usage
-- END OF FILE
=====================================
[michael at localhost ~]$ ghc ex14.hs -o ex14
ex14.o: In function `rF8_info':
(.text+0x48): undefined reference to `mtlzm1zi1zi0zi2_ControlziMonadziError_zdf17_closure'
ex14.o: In function `sGp_info':
(.text+0x861): undefined reference to `mtlzm1zi1zi0zi2_ControlziMonadziError_zdf17_closure'
ex14.o: In function `sGp_info':
(.text+0x91d): undefined reference to `__stginit_mtlzm1zi1zi0zi2_ControlziMonadziError_'
ex14.o: In function `rF8_info':
(.text+0x50): undefined reference to `mtlzm1zi1zi0zi2_ControlziMonadziErrorziClass_zdp1MonadError_info'
ex14.o: In function `sGp_info':
(.text+0x869): undefined reference to `mtlzm1zi1zi0zi2_ControlziMonadziErrorziClass_catchError_info'
ex14.o: In function `rF8_srt':
(.data+0x0): undefined reference to `mtlzm1zi1zi0zi2_ControlziMonadziError_zdf17_closure'
ex14.o: In function `Main_main_srt':
(.data+0x6c): undefined reference to `mtlzm1zi1zi0zi2_ControlziMonadziError_zdf17_closure'
collect2: ld returned 1 exit status
[michael at localhost ~]$
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090515/c86ac583/attachment-0001.html
More information about the Haskell-Cafe
mailing list