簡體   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