我嘗試了幾個項目目前轉換爲classy-prelude
。雖然大多數行爲似乎對我來說很簡單,但(head . head)
在簡單的2D列表上給出了神祕的錯誤。優雅-序曲(頭。頭)
考慮以下GHCI會議:
Prelude> (head . head) [[1,2],[3,4]]
1
讓我們試試這個與ghci -XNoImplicitPrelude
和classy-prelude
:
> import ClassyPrelude
ClassyPrelude> (head . head) [[1,2],[3,4]]
<interactive>:10:1:
Couldn't match type `MinLen (Succ nat1) mono1' with `[[t0]]'
Expected type: [[t0]] -> Element mono0
Actual type: MinLen (Succ nat1) mono1 -> Element mono0
The function `head . head' is applied to one argument,
but its type `MinLen (Succ nat1) mono1 -> Element mono0'
has only one
In the expression: (head . head) [[1, 2], [3, 4]]
In an equation for `it': it = (head . head) [[1, 2], [3, 4]]
我認爲GHC根本無法正確解析類型多維名單。有沒有什麼辦法可以幫助它,而不訴諸於(Prelude.head . Prelude.head)
?
'MinLen(Succ nat1)mono1' =>我認爲你需要一個非空列表類型 –
@MauricioScheffer你到底在哪裏我想要一個非空列表? '[[1,2],[3,4]]'是在兩個維度是非空的,並且GHC * *應該能夠從它派生一個Int類型(它可以爲'Prelude.head'做) –
@UliKöhler我認爲MauricioScheffer是對的。這些列表非空,但它們的*類型*不是「非空列表」類型。 –