diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | dependent-enummap.cabal | 14 | ||||
-rw-r--r-- | test/Main.hs | 38 |
3 files changed, 52 insertions, 1 deletions
@@ -1 +1,2 @@ dist-newstyle/ +cabal.project.local diff --git a/dependent-enummap.cabal b/dependent-enummap.cabal index 8005de5..ea96988 100644 --- a/dependent-enummap.cabal +++ b/dependent-enummap.cabal @@ -13,7 +13,19 @@ library base >=4.15, containers, dependent-sum, - some + some, hs-source-dirs: src default-language: Haskell2010 ghc-options: -Wall + +test-suite test + type: exitcode-stdio-1.0 + main-is: Main.hs + build-depends: + base, + dependent-enummap, + dependent-sum, + some, + hs-source-dirs: test + default-language: Haskell2010 + ghc-options: -Wall diff --git a/test/Main.hs b/test/Main.hs new file mode 100644 index 0000000..19f56e2 --- /dev/null +++ b/test/Main.hs @@ -0,0 +1,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] |