kakkun61
haskell-org-status に https://status.haskell.org/ の RSS を流すようにしてみました
data (Show a) => Color a = Red | Green | Blue | Rgb {r :: a, g :: a, b :: a} deriving (Show)
data (Show a) => Color a where Red :: Color Green :: Color Blue :: Color Rgb :: {r ::a, g :: a, b :: a} -> Color deriving (Show)
data Color a where Red :: Color Green :: Color Blue :: Color Rgb :: (Show a) => {r ::a, g :: a, b :: a} -> Color deriving (Show)
{-# LANGUAGE GADTs #-} data Color a where Red :: Color Green :: Color Blue :: Color Rgb :: (Show a) => {r ::a, g :: a, b :: a} -> Color deriving (Show) main = print (Red :: (Color Integer))
prog.hs:3:10: error: • Expecting one more argument to ‘Color’ Expected a type, but ‘Color’ has kind ‘k0 -> *’ • In the type ‘Color’ In the definition of data constructor ‘Red’ In the data declaration for ‘Color’ | 3 | Red :: Color | ^^^^^
data Color a where Red :: Color a Green :: Color a Blue :: Color a Rgb :: (Show a) => {r ::a, g :: a, b :: a} -> Color a deriving (Show) main = print (Red :: (Color Integer))
prog.hs:7:13: error: • Can't make a derived instance of ‘Show (Color a)’: Constructor ‘Rgb’ has constraints in its type Possible fix: use a standalone deriving declaration instead • In the data declaration for ‘Color’ | 7 | deriving (Show) |
{-# LANGUAGE GADTs #-} data (Show a) => Color a where Red :: Color a Green :: Color a Blue :: Color a Rgb :: {r ::a, g :: a, b :: a} -> Color a deriving (Show) main = print (Red :: (Color Integer))
{-# LANGUAGE GADTs #-} data Color a where Red :: (Show a) => Color a Green :: (Show a) => Color a Blue :: (Show a) => Color a Rgb :: (Show a) => {r ::a, g :: a, b :: a} -> Color a deriving (Show) main = print (Red :: (Color Integer))
prog.hs:7:13: error: • Can't make a derived instance of ‘Show (Color a)’: Constructor ‘Red’ has constraints in its type Constructor ‘Green’ has constraints in its type Constructor ‘Blue’ has constraints in its type Constructor ‘Rgb’ has constraints in its type Possible fix: use a standalone deriving declaration instead • In the data declaration for ‘Color’ | 7 | deriving (Show) | ^^^^
Show
インスタンスを定義するか、どうしてもやりたければ https://haskell-jp.slack.com/archives/C5666B6BB/p1507884910000527 でも触れているとおり DatatypeContexts
を使えばよいのではないかと。data Color a = Red | Green | Blue | Rgb {r :: a, g :: a, b :: a} deriving (Show)
{-# LANGUAGE GADTs, StandaloneDeriving #-} data Color a where Red :: (Show a) => Color a Green :: (Show a) => Color a Blue :: (Show a) => Color a Rgb :: (Show a) => {r ::a, g :: a, b :: a} -> Color a deriving instance Show (Color a) main = print (Red :: (Color Integer))