The other simple option is to eta-expand: > let myprint x = print x will get the correct type,
The monomorphism restriction is to stop things that look like *values* whose computation results are memoized, from turning into *functions* which need a dictionary context and get recomputed every time they are accessed. In your declaration, "myprint" looks like a value, so it should only get computed once. In order to do this it needs to be monomorphic, because otherwise it could have a different value depending on where it was used. -- ryan On Wed, Dec 10, 2008 at 10:55 PM, Janis Voigtlaender <vo...@tcs.inf.tu-dresden.de> wrote: > 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:vo...@tcs.inf.tu-dresden.de > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe