[Haskell-cafe] Ambiguous type variable
jacek.generowicz at cern.ch
Fri Oct 15 19:38:13 EDT 2010
<jacek.generowicz at cern.ch> wrote:
> -- Given a definition of view which is essentially a synonym for
> 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
On 2010 Oct 16, at 01:25, Daniel Fischer wrote:
> Defaulting only takes place when all involved classes are defined in
> Prelude or the standard libraries.
> Your View class isn't, hence there's no defaulting.
Bingo. Thank you.
More information about the Haskell-Cafe