Created
May 16, 2016 20:48
-
-
Save sirlensalot/05c90efb53951cfcd2806de129520e83 to your computer and use it in GitHub Desktop.
Index a type with two Nats with "restricted proxy"
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 KindSignatures #-} | |
{-# LANGUAGE GADTs, DataKinds, PolyKinds, ScopedTypeVariables #-} | |
module Foo where | |
import GHC.TypeLits | |
import Data.Proxy | |
data Foo (a :: Nat) (b :: Nat) :: * where Foo :: Foo a b | |
instance (KnownNat a, KnownNat b) => Show (Foo a b) where | |
show Foo = "Foo :: Foo " ++ show (natVal (Proxy :: Proxy a)) ++ " " ++ | |
show (natVal (Proxy :: Proxy a)) | |
bar :: Foo 1 2 | |
bar = Foo | |
{- | |
λ> bar | |
Foo :: Foo 1 1 | |
λ> :set -XDataKinds | |
λ> Foo :: Foo 1 1 | |
Foo :: Foo 1 1 | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment