[Haskell-beginners] Help on first program

John M. Dlugosz ngnr63q02 at sneakemail.com
Fri Mar 28 23:02:26 UTC 2014


Nevermind... it really is too few arguments.


On 3/28/2014 6:00 PM, John M. Dlugosz wrote:
> Can someone explain what's wrong here?  What is the code below _really_ saying, vs what I
> meant?  I don't understand the error messages yet.
>
>          == input ==
> module Main (
>      main
> ) where
>
> solve n src dest tmp =
>      do solve (n-1) src tmp      -- line 6
>         solve 1 src dest tmp
>         solve (n-1) tmp dest    -- line 8
>
> solve 1 src dest _ =
>      putStrLn "move a disk from " ++ src ++ " to " ++ dest    -- line 11
>
>
> main = do
>      putStrLn "Towers of Hanoi problem"
>      solve 5 "A" "B" "C"
>
>
>          == output ==
> Prelude> :reload
> [1 of 1] Compiling Main             ( towers1.hs, interpreted )
> Failed, modules loaded: none.
> Prelude>
> towers1.hs:6:8:
>      Couldn't match expected type `[a0]'
>                  with actual type `[Char] -> [Char]'
>      In the return type of a call of `solve'
>      Probable cause: `solve' is applied to too few arguments
>      In a stmt of a 'do' block: solve (n - 1) src tmp
>      In the expression:
>        do { solve (n - 1) src tmp;
>             solve 1 src dest tmp;
>             solve (n - 1) tmp dest }
>
> towers1.hs:8:8:
>      Couldn't match expected type `[Char]'
>                  with actual type `[Char] -> [Char]'
>      In the return type of a call of `solve'
>      Probable cause: `solve' is applied to too few arguments
>      In a stmt of a 'do' block: solve (n - 1) tmp dest
>      In the expression:
>        do { solve (n - 1) src tmp;
>             solve 1 src dest tmp;
>             solve (n - 1) tmp dest }
>
> towers1.hs:11:5:
>      Couldn't match expected type `[Char]' with actual type `IO ()'
>      In the return type of a call of `putStrLn'
>      In the first argument of `(++)', namely
>        `putStrLn "move a disk from "'
>      In the expression:
>        putStrLn "move a disk from " ++ src ++ " to " ++ dest
>




More information about the Beginners mailing list