[Haskell] Going nuts

ChrisK chrisk at MIT.EDU
Wed Apr 20 23:32:48 EDT 2005


On Apr 20, 2005, at 10:04 PM, Alexandre Weffort Thenorio wrote:

> As usual a beginner in Haskell. Trying to write a simple program in 
> haskel
> shown below
>

> outputLine keyno key orgFile = do
>     part1 <- getLeft keyno orgFile
>     part2 <- getRight keyno orgFile
>     total <- part1 ++ (strUpper key) ++ part2 ++ "\n"

This is just creating a new expression bound to total, not an action.
Instead of <- use let =

      let total = part1 ++ (strUpper key) ++ part2 ++ "\n"

Something about Lists [] also being a Monad gave a confusing error 
message to you

>     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
>
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell



More information about the Haskell mailing list