Skip to content

Instantly share code, notes, and snippets.

@sirlensalot
Created May 16, 2016 20:48
Show Gist options
  • Save sirlensalot/05c90efb53951cfcd2806de129520e83 to your computer and use it in GitHub Desktop.
Save sirlensalot/05c90efb53951cfcd2806de129520e83 to your computer and use it in GitHub Desktop.
Index a type with two Nats with "restricted proxy"
{-# 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