這將編譯:如何指定子表達式的多態類型?
foo :: (Bounded a,Enum a) => a -> Int
foo x = length ([minBound .. x] ++ drop 1 [x .. maxBound])
這並不編譯:
foo :: (Bounded a,Enum a) => a -> Int
foo x = length ([minBound .. maxBound] :: [a])
我認爲第二個示例不編譯,因爲在類型簽名類型a
是不一樣的一箇中子表達式的類型簽名。我怎樣才能使子表達式的類型引用上面給出的多態類型?
我想你正在尋找ScopedTypeVariables擴展。 – gigabytes