I have wrote one function which has a signature of
sort :: [Int] -> [Int]
which gives me an error of
Ambiguous occurrence ‘sort’
I know there is already a built-in function called sort in
import Data.List
How can i fix this issue while keeping the same type signature?
You can try
import Data.List hiding (sort)
This will prevent Data.List.sort
from being imported, leaving you free to define your own function called sort
.
If you want to be able to use Data.List.sort
in addition to your own, also add the line
import qualified Data.List
or
import qualified Data.List as L
This allows you to to access the library function as Data.List.sort
or L.sort
, respectively.
Try qualifying the name:
module Foo where
import Data.List as L
Then, to refer to the library sort
, use L.sort
. For the user-defined sort, use Foo.sort
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With