[Haskell-cafe] Ambiguous type variable

Jacek Generowicz 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
> 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



On 2010 Oct 16, at 01:25, Daniel Fischer wrote:

> http://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-790004.3.4
>
> Defaulting only takes place when all involved classes are defined in  
> the
> Prelude or the standard libraries.
>
> Your View class isn't, hence there's no defaulting.

Bingo. Thank you.



More information about the Haskell-Cafe mailing list