GHC 7.8 中的 OverloadedLists 语言 pragma 非常吸引人,所以我决定尝试一下:
{-# LANGUAGE OverloadedLists #-}
import Data.Set (Set)
import qualified Data.Set as Set
mySet :: Set Int
mySet = [1,2,3]
编译器给了我:
No instance for (GHC.Exts.IsList (Set Int))
arising from an overloaded list
In the expression: [1, 2, 3]
In an equation for ‘mySet’: mySet = [1, 2, 3]
No instance for (Num (GHC.Exts.Item (Set Int)))
arising from the literal ‘1’
In the expression: 1
In the expression: [1, 2, 3]
In an equation for ‘mySet’: mySet = [1, 2, 3]
Failed, modules loaded: none.
即使是发行说明中的示例也不起作用:
> ['0' .. '9'] :: Set Char
<interactive>:5:1:
Couldn't match type ‘GHC.Exts.Item (Set Char)’ with ‘Char’
Expected type: [Char] -> Set Char
Actual type: [GHC.Exts.Item (Set Char)] -> Set Char
In the expression: ['0' .. '9'] :: Set Char
In an equation for ‘it’: it = ['0' .. '9'] :: Set Char
有谁知道这里发生了什么?