Skip to content

Instantly share code, notes, and snippets.

@gnumonik
Created January 8, 2021 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnumonik/2bbda78c261cb36fcc492d33d2f0a54e to your computer and use it in GitHub Desktop.
Save gnumonik/2bbda78c261cb36fcc492d33d2f0a54e to your computer and use it in GitHub Desktop.
data Counter :: Nat -> Type where
Counter :: (KnownNat s) => Sing s -> Counter s
data ACounter :: Type where
ACounter :: (KnownNat s, KnownNat (s + 1)) => Counter s -> ACounter
incCounter :: forall a. (KnownNat a, KnownNat (a + 1)) => Counter a -> Counter (a + 1)
incCounter _ = Counter $ sing @(a + 1)
zero :: Counter 0
zero = Counter (sing @0)
-- incCounter works...
-- > (\(Counter x) -> fromSing x) $ incCounter (incCounter zero)
-- 2
--existential version doesn't...
incCounterS :: ACounter -> ACounter
incCounterS (ACounter c) = ACounter $ incCounter c -- Could not deduce
-- (KnownNat((s GHC.TypeNats.+ 1) GHC.TypeNats.+ 1))
-- arising from a use of 'ACounter' (...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment