簡體   English   中英

函數組合參數在Haskell中的應用

[英]Application of arguments to function composition in Haskell

作為Haskell的新手我無法理解為什么表達head . words “one two three four” head . words “one two three four”拋出異常和功能組成head . words 必須使用$運算符應用head . words - 右側的表達式不需要進一步評估,因為它只是一個String 編譯它的另一種方法是放head . words 括號中的head . words但是(head . words) :: String -> Stringhead . words :: String -> String類型相同head . words :: String -> String head . words :: String -> String所以為什么把它放在括號中會使表達式編譯?

因為優先規則。 應用程序具有最高優先級; $ - 最低。

head . words “one two three four” head . words “one two three four”被解析為head . (words “one two three four”) head . (words “one two three four”)即應用於字符串的words必須產生一個函數(如(.)所要求的)。 但這不是words的類型:

Prelude> :t words
words :: String -> [String]

head . words $ “one two three four” 另一方面, head . words $ “one two three four”被解析為(head . words) “one two three four” head。words (head . words) “one two three four”並且類型適合。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM