I've been following the GHC.Generics tutorial to make a simple generic typeclass for providing default values for arbitrary types. However when I try to load my file (relevant snippet, which still produces the error)
{-# 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
I get the following error:
Generic.hs:12:46:
The first argument of ‘:+:’ should have kind ‘* -> *’,
but ‘a’ has kind ‘*’
In the instance declaration for ‘GDefault (a :+: b)’
What am I doing wrong?
Don't you mean...?
instance (GDefault a, GDefault b) => GDefault (a :+: b) where ...
-- ^ ^
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.