Last active
March 30, 2018 01:27
-
-
Save deepfire/1dd56cf9ddcb1438996f70702f8a6d24 to your computer and use it in GitHub Desktop.
ghci SOP.hs
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 GADTs #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeInType #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
import GHC.Types | |
import GHC.TypeLits | |
data NS (a :: k -> Type) (b :: [k]) where | |
Z :: forall k (a :: k -> Type) (x :: k) (xs :: [k]). (a x) -> NS a (x : xs) | |
data NP (a :: k -> Type) (b :: [k]) where | |
S :: forall k (a :: k -> Type) (x :: k) (xs :: [k]). (a x) -> NP a (x : xs) | |
type family IndexNP np ns where | |
-- IndexNP (NP f (x:_)) (NS _ (y:'[])) = TypeError (Text "Boo.") | |
IndexNP np ns = TypeError (Text "Irreducible.") | |
-- As expected: | |
*Main> :kind! forall f x1 xs1 g x2 xs2. IndexNP (NP f (x1 : xs1)) (NS g (x2 : xs2)) | |
forall f x1 xs1 g x2 xs2. IndexNP (NP f (x1 : xs1)) (NS g (x2 : xs2)) :: k | |
= (TypeError ...) | |
--- | |
--- Now, let's add a clause to the family: | |
--- | |
type family IndexNP np ns where | |
IndexNP (NP f (x:_)) (NS _ (y:'[])) = TypeError (Text "Boo.") | |
IndexNP np ns = TypeError (Text "Irreducible.") | |
-- Not expected: | |
*Main> :kind! forall f x1 xs1 g x2 xs2. IndexNP (NP f (x1 : xs1)) (NS g (x2 : xs2)) | |
forall f x1 xs1 g x2 xs2. IndexNP (NP f (x1 : xs1)) (NS g (x2 : xs2)) :: k | |
= IndexNP (NP f (x1 : xs1)) (NS g (x2 : xs2)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment