[Haskell-cafe] Re: [Haskell] Going nuts
Albert Lai
trebla at vex.net
Wed Apr 20 23:48:28 EDT 2005
"Alexandre Weffort Thenorio" <alethenorio at home.se> writes:
> 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))
outputLine keyno key orgFile = do
let part1 = getLeft keyno orgFile
let part2 = getRight keyno orgFile
let total = part1 ++ (strUpper key) ++ part2 ++ "\n"
newHexFile <- openFileEx "newfile" (BinaryMode WriteMode)
hPutStrLn newHexFile (orgFile!!0 ++ "\n" ++ total ++ unlines (drop 2 orgFile))
"let ... =" instead of "<-" because getLeft et al. aren't IO commands.
(Why type error rather than syntax error then? Because getLeft returns
a list, and list is a monad too. E.g.,
do { part1 <- getLeft keyno orgFile; return part1 }
= [ part1 | part1 <- getLeft keyno orgFile ]
so part1 is inferred to be a Char.)
There will be another problem. The type of orgFile is expected to be
String here, but the callsite gives it "lines(hexFile)" of type [String].
More information about the Haskell-Cafe
mailing list