相关疑难解决方法(0)

声明IsString实例时出现"非法实例声明"

我正在编写一个使用UTF-16字符串的应用程序,并且为了利用重载的字符串扩展,我试图IsString为它创建一个实例:

import Data.Word ( Word16 )
import Data.String ( IsString(fromString) )

type String16 = [Word16]

instance IsString [Word16] where
    fromString = encodeUTF16

encodeUTF16 :: String -> String16
Run Code Online (Sandbox Code Playgroud)

问题是,当我尝试编译模块时,GHC 7.0.3抱怨:

Data/String16.hs:35:10:
    Illegal instance declaration for `IsString [Word16]'
      (All instance types must be of the form (T a1 ... an)
       where a1 ... an are *distinct type variables*,
       and each type variable appears at most once in the instance head.
       Use -XFlexibleInstances if you want to disable this.)
    In the …
Run Code Online (Sandbox Code Playgroud)

haskell typeclass

29
推荐指数
1
解决办法
7278
查看次数

标签 统计

haskell ×1

typeclass ×1