Ambiguous Occurrence

后端 未结 2 1727
醉酒成梦
醉酒成梦 2021-02-08 06:20

I am currently learning how to write type classes. I can\'t seem to write the Ord type class with compile errors of ambiguous occurrence.

module Practice where

         


        
相关标签:
2条回答
  • 2021-02-08 06:45

    hammar is right, it's because of clashing with standard Prelude names. But there are another solutions in addition to hiding names from Prelude.

    You can import Prelude qualified:

    module Practice where
    
    import qualified Prelude as P
    
    ...
    

    Next, you can gain access to both you and standard version of function: max will execute your version, and P.max will execute standard Prelude's.

    There is also way to completely hide all standard Prelude functions: GHC's extension NoImplicitPrelude (http://www.haskell.org/haskellwiki/No_import_of_Prelude). It can be activated writing

    {-# LANGUAGE NoImplicitPrelude #-}
    

    in the very beginning of your file

    0 讨论(0)
  • 2021-02-08 06:53

    The problem is that the names of your functions are clashing with the standard ones from the Prelude.

    To solve this, you can add an explicit import declaration which hides the conflicting names:

    module Practice where
    
    import Prelude hiding (Ord, compare, (<), (<=), (>=), (>), max, min)
    
    ...
    
    0 讨论(0)
提交回复
热议问题