Mac*_*cki 2 haskell types typeclass ghc
我一直在关注GHC.Generics教程,制作一个简单的通用类型类,为任意类型提供默认值.但是,当我尝试加载我的文件(相关片段,仍然产生错误)
{-# LANGUAGE DefaultSignatures, DeriveGeneric, TypeOperators, FlexibleContexts #-}
import GHC.Generics
class Default a where
def :: a
default def :: (Generic a, GDefault (Rep a)) => a
def = to gdef
class GDefault f where
gdef :: f a
instance (Default a, Default b) => GDefault (a :+: b) where
gdef (L1 x) = gdef x
gdef (R1 x) = gdef x
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Generic.hs:12:46:
The first argument of ‘:+:’ should have kind ‘* -> *’,
but ‘a’ has kind ‘*’
In the instance declaration for ‘GDefault (a :+: b)’
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
你的意思是......?
instance (GDefault a, GDefault b) => GDefault (a :+: b) where ...
-- ^ ^
Run Code Online (Sandbox Code Playgroud)