Blnpwr
Blnpwr

Reputation: 1875

Map function haskell

I am getting this error when I compile:

Ambigous occurence 'map'
It could refer to either Main.map defined at blablabla

I read a similar post here and tried this :

import qualified Data.Map as Map

map                     :: (a->b) -> [a] -> [b]
map f  []               =  []
map f (x:xs)            =  f x : map f xs

I am still getting the error. I am compiling on GHCI.

How can I avoid this ?

Upvotes: 0

Views: 308

Answers (1)

user2970277
user2970277

Reputation:

You're getting the error because the standard prelude (which is imported by default) alrready has a map function in it.

If you're practising it makes sense to use your own new name for the function. That way you can check yours works the same way as the original. Put a dash' after the name, or call it mymap or something.

You can also do an explicit import so you can leave map out:

import Prelude hiding (map)

but I thinks it's less faf to think of your own non-conflicting name.

Upvotes: 5

Related Questions