繁体   English   中英

使用GHC泛型时参数类型错误

[英]Wrong argument kind when using GHC Generics

我一直在遵循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

我收到以下错误:

Generic.hs:12:46:
    The first argument of ‘:+:’ should have kind ‘* -> *’,
      but ‘a’ has kind ‘*’
    In the instance declaration for ‘GDefault (a :+: b)’

我究竟做错了什么?

你不是说...吗?

instance (GDefault a, GDefault b) => GDefault (a :+: b) where ...
  --      ^           ^

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM