this is another case of the terrible restriction of monomorphism
There are several ways around this:
add point
let wordSet ws = foldl (\se -> Data.Set.insert es) Data.Set.empty ws
disable restriction
> :set -XNoMonomorphismRestriction > let wordSet = foldl (\se -> Data.Set.insert es) Data.Set.empty > :t wordSet wordSet :: Ord a => [a] -> containers-0.5.0.0:Data.Set.Base.Set a
add type signatures inside GHCi (thanks @Zeta)
let{ wordSet :: Ord e => [e] -> Data.Set.Set e; wordSet = foldl (\se -> Data.Set.insert es) Data.Set.empty}
use and load the source file (with signature type)
module WordSet where import Data.Set (Set, insert, empty) wordSet :: (Ord e) => [e] -> Set e wordSet = foldl (\se -> insert es) empty
use and load the source file (disable restriction)
{-# LANGUAGE NoMonomorphismRestriction #-} module WordSet where import Data.Set (Set, insert, empty) wordSet = foldl (\se -> insert es) empty
note: this one is not idiomatic since you must give signatures to the top-level definitions (most likely, the GHC warns you).
source share