On 16 October 2010 09:47, Jacek Generowicz <jacek.generow...@cern.ch> wrote: > -- Given a definition of view which is essentially a synonym for show: > > class View a where > view :: a -> String > > instance View Int where > view = show > > -- why does "show 2" compile, while "view 2" gives an > -- 'Ambiguous type variable' error > > fine = view (2::Int) > noProblem = show 2 > ambiguousTypeVariable = view 2
"2" is a generic number. If you don't specify a type, it usually defaults to Integer. All Num instances that come in the Prelude have Show instances, so no matter which gets picked "show 2" works. However, when you say "view 2" ghc/ghci doesn't know that you want 2 to be an Int (as that's the only type you have an instance for View for). -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe