[Haskell-beginners] 99problems: different response from ghci <--> runhaskell / ghc

GiGi looeegee at gmail.com
Fri Aug 17 10:53:19 CEST 2012


Hi all,
trying to solve the problem 6  "reverse a list"
I'm getting a different behaviour from ghci / runhaskell.

main = do
  putStrLn $ concat (map show (myReverse [1,2,3]))
  -- putStrLn $ concat (map show (myReverse []))

myReverse :: [a] -> [a]
myReverse [] = []
myReverse (x:xs) = go [] (x:xs)
    where go :: [a] -> [a] -> [a]
          go curr (x:xs) | null xs  =  [x] ++ curr
          go curr (x:xs)  =  go ([x] ++ curr) xs


the second putStrLn (once uncommented) gives this error in the
runhaskell/ghc:
         Ambiguous type variable `a0' in the constraint:
      (Show a0) arising from a use of `show'
    Probable fix: add a type signature that fixes these type variable(s)
    In the first argument of `map', namely `show'

_but_   if I load the same source into ghci I can successfully enter&run
the command:

Prelude> :reload
[1 of 1] Compiling Main             ( 05.hs, interpreted )
Ok, modules loaded: Main.
*Main> putStrLn $ concat (map show (myReverse []))

*Main>


Then if I "help" the type inference changing the myReverse type declaration
to:

myReverse :: [Int] -> [Int]


everything works well

So, my question is:  _where_ is the difference between ghci / runhaskell?

thx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120817/9a35fbe3/attachment.htm>


More information about the Beginners mailing list