blob: 19f56e29bbb463854f12df195b62954997c5f961 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import qualified Data.Dependent.EnumMap.Strict as DE
import Data.Dependent.Sum
import Data.Some
data Tag = A | B | C
deriving (Show)
data STag tag where
SA :: STag A
SB :: STag B
SC :: STag C
deriving instance Show (STag tag)
instance DE.Enum1 STag where
type Enum1Info STag = ()
fromEnum1 = \case { SA -> (0, ()); SB -> (1, ()); SC -> (2, ()) }
toEnum1 n () = case n of { 0 -> Some SA; 1 -> Some SB; 2 -> Some SC; _ -> error "invalid tag" }
data Value tag where
VA :: Int -> Value A
VB :: Bool -> Value B
VC :: String -> Value c
deriving instance Show (Value tag)
main :: IO ()
main = do
print $ DE.fromList @STag @Value []
print $ DE.fromList [SB :=> VB False, SA :=> VA 3]
|