Can we specify the module of the function being referred

Dear listers, I was writing a program which defines a function named "show". But at each of the recursive calls to itself "ghci" is showing the following message: ' Ambiguous occurrence `show' It could refer to either `show', defined at temp.hs:5:0 or `show', imported from Prelude ' I don't want to import the 'show' function from prelude. Is there any way out or I have to declare instance of the 'Show'? Can we specify the module of a function from which it will be referred? -- Amit kumar Dhar

Amit Kumar Dhar wrote:
I don't want to import the 'show' function from prelude. Is there any way out or I have to declare instance of the 'Show'?
The prelude is only implicitly imported, if it is not explicitly imported. That means that you can explicitly say import Prelude hiding (show) to get rid of Prelude's show.
Can we specify the module of a function from which it will be referred?
You can give a module a name while importing it, and then use this name with a dot. For your situation, maybe the following two import statements make sense: -- bring everything except show into scope import Prelude hiding (show) -- make Prelude's show available as P.show import qualified Prelude as P Now you can even use Prelude's show in the definition of your own show. Here is an example, showing lists with set notation: show :: [Int] -> String show xs = "{" ++ content ++ "}" where content = concat (intersperse ", " (map P.show xs)) (use "import Data.List" for intersperse).
I was writing a program which defines a function named "show".
While it is not wrong to use a name from the Prelude for something else, it is often confusing, so I would consider using some other name (display, toString, prettyPrint, ...). Tillmann
participants (2)
-
Amit Kumar Dhar
-
Tillmann Rendel