Created
January 25, 2021 02:29
-
-
Save kquick/a6411a70068f3e4faaba42ac2c29a3f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
module Main where | |
import Data.Parameterized.Classes | |
import Data.Parameterized.Context | |
import qualified Data.Parameterized.Context.Unsafe as U | |
data (Show t) => MyMaybe t = MyJust t | MyNothing | |
instance ShowF MyMaybe | |
instance Show (MyMaybe t) where show = showF | |
type TestCtx = U.EmptyCtx '::> Int '::> String '::> Int '::> Bool | |
mkUMyMaybe :: U.Assignment MyMaybe TestCtx | |
mkUMyMaybe = U.generate U.knownSize setMyValue | |
setMyValue :: U.Index TestCtx tp -> MyMaybe tp | |
setMyValue idx | |
| Just Refl <- testEquality (U.lastIndex U.knownSize) idx = MyJust False | |
| Just Refl <- testEquality (U.skipIndex $ U.skipIndex $ U.skipIndex U.baseIndex) idx = MyJust 1 | |
| Just Refl <- testEquality (U.skipIndex $ U.skipIndex $ U.nextIndex U.knownSize) idx = MyJust "two" | |
| Just Refl <- testEquality (U.skipIndex $ U.nextIndex U.knownSize) idx = MyJust 3 | |
main = do putStrLn "start" | |
putStrLn $ show $ U.sizeInt (U.size mkUMyMaybe) | |
putStrLn $ show mkUMyMaybe | |
putStrLn "end" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment