我知道String被定义为[Char],但我想在类实例中区分它们.除了使用newtype创建一个单独的类型之外,是否可以使用一些聪明的技巧?我想做的事情如下:
class Something a where
doSomething :: a -> a
instance Something String where
doSomething = id
instance (Something a) => Something [a] where
doSomething = doSoemthingElse
Run Code Online (Sandbox Code Playgroud)
当我用doSomething ("a" :: [Char])和调用它时得到不同的结果doSomething ("a" :: String).
我知道FlexibleInstances,OverlappingInstances但他们显然不会削减案件.