How to fix an ambiguous error error in Haskell

I wrote one function that has a signature

sort :: [Int] -> [Int]

what gives me an error

Ambiguous appearance

I know that there is already a built-in function called sort in

import Data.List

How can I fix this problem by keeping the signature of the same type?

+4
source share
2 answers

You can try

import Data.List hiding (sort)

This will prevent import Data.List.sort, allowing you to freely define your own function with a name sort.

If you want to use Data.List.sortin addition to yours, add the line

import qualified Data.List

or

import qualified Data.List as L

This allows you to access the library function as Data.List.sortor L.sort, respectively.

+6

:

module Foo where

import Data.List as L

, sort, L.sort. Foo.sort .

+2

Source: https://habr.com/ru/post/1662788/


All Articles