cib*_*en1 3 haskell operator-overloading
这篇文章提出了案件的问题!!.接受的答案告诉我们,您实际在做的是创建一个新功能!!,然后您应该避免导入标准功能.
但是,如果将新功能应用于不同类型而不是标准功能,为什么要这样做呢?编译器是否能够根据其参数选择正确的编译器?是否有任何编译器标志允许这个?
例如,如果*没有定义[Float] * Float
为什么编译器会哭
> Ambiguous occurrence * > It could refer to either `Main.*', defined at Vec.hs:4:1 > or `Prelude.*',
对于此代码:
(*) :: [Float] -> Float -> [Float]
(*) as k = map (\a -> a*k) as -- here: clearly Float*Float
r = [1.0, 2.0, 3.0] :: [Float]
s = r * 2.0 -- here: clearly [Float] * Float
main = do
print r
print s
Run Code Online (Sandbox Code Playgroud)