[Haskell] Going nuts
Alexandre Weffort Thenorio
alethenorio at home.se
Wed Apr 20 22:04:32 EDT 2005
As usual a beginner in Haskell. Trying to write a simple program in haskel
shown below
main :: IO()
main =catch (do
hexFile <- readFile "file"
putStr "What is the key number (0 or 1)?\n"
keyno <- getLine
putStr "Input key.\n"
key <- getLine
newLine <- outputLine keyno key (lines(hexFile))
bla bla bla........
getLeft :: String -> String -> String
getLeft _ [] = ""
getLeft key line
|key == "0" = take 9 line
|otherwise = take 25 line
getRight :: String ->String -> String
getRight _ [] = ""
getRight key line
|key == "0" = drop 25 line
|otherwise = drop 41 line
outputLine keyno key orgFile = do
part1 <- getLeft keyno orgFile
part2 <- getRight keyno orgFile
total <- part1 ++ (strUpper key) ++ part2 ++ "\n"
newHexFile <- openFileEx "newfile" (BinaryMode WriteMode)
hPutStrLn newHexFile (orgFile!!0 ++ "\n" ++ total ++ unlines (drop 2
orgFile))
strUpper :: String -> String
strUpper [] = ""
--strUpper x:xs = (toUpper x):(strUpper xs)
And I keep getting the error
changecode.hs:42:
Couldn't match `[a]' against `Char'
Expected type: [a]
Inferred type: Char
In the first argument of `(++)', namely `part1'
In a 'do' expression:
total <- part1 ++ ((strUpper key) ++ (part2 ++ "\n"))
I have tried thousands and thousand of modifications (Originally getLeft and
getRight didn't exist, the code was part of outputLine) but it keeps
thinking that orgFile is a String when clearlly it is a [String]. Also I can
get my function strUpper (Which simply puts strings to Upper case) to work.
Can anybody see what is wrong here?
Best Regards
Alex
More information about the Haskell
mailing list