Cetin Sert wrote:
Hi,

Why does this not function?

Prelude> sequence [print 'a', print 2]
'a'
2
[(),()]
*Prelude> let myprint = print*
*Prelude> sequence [myprint 'a', myprint 2]*

<interactive>:1:18:
    Couldn't match expected type `()' against inferred type `Char'
    In the first argument of `myprint', namely 'a'
    In the expression: myprint 'a'
    In the first argument of `sequence', namely
        `[myprint 'a', myprint 2]'

The problem is the monomorphism restriction:

~> ghci
GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
Prelude> :t print
print :: (Show a) => a -> IO ()
Prelude> let myprint=print
Prelude> :t myprint
myprint :: () -> IO ()
Prelude> :q
Leaving GHCi.
~> ghci -fno-monomorphism-restriction
GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
Prelude> let myprint=print
Prelude> :t myprint
myprint :: (Show a) => a -> IO ()

Can providing some type annotations (interactively in ghci or in some .hs file) help solve the problem?

Yes.

--
Dr. Janis Voigtlaender
http://wwwtcs.inf.tu-dresden.de/~voigt/
mailto:[EMAIL PROTECTED]
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to