小编Edw*_*ley的帖子

Haskell:为包含在另一种类型中的类型使用正确的实例

假设我们有以下代码,其中有两种类型最终放在另外两种类型中,其中最外面的是GADT:

{-# LANGUAGE FlexibleInstances,
             GADTSyntax,
             GADTs,
             OverlappingInstances,
             StandaloneDeriving #-}

data SomeType1 = SomeType1 deriving Show
data SomeType2 = SomeType2 deriving Show

class SomeClass d where

instance SomeClass SomeType1 where
instance SomeClass SomeType2 where

data WrapperType t where
  WrapperType :: (SomeClass t, Show t) => t -> (WrapperType t)

instance Show (WrapperType SomeType1) where
  show (WrapperType d) = "correct"

instance Show (WrapperType t) where
  show (WrapperType d) = "incorrect"

data ListWrap where
  ListWrap :: [(WrapperType d)] -> ListWrap

deriving instance Show …
Run Code Online (Sandbox Code Playgroud)

haskell types

5
推荐指数
1
解决办法
133
查看次数

标签 统计

haskell ×1

types ×1