Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# Language GADTSyntax,ExistentialQuantification,TypeOperators,PolyKinds,DataKinds,TypeFamilies,TypeInType ,DatatypeContexts#-}
  2.  
  3. import GHC.Exts
  4.  
  5. type family State (x :: * -> * -> *) :: Constraint where
  6.  State Basecase = ()
  7.  State (Nested xs) = ()
  8.  
  9. data Basecase s a where
  10.  Stream' :: Stream s a -> Basecase s a
  11. Linear' :: Linear s a -> Basecase s a
  12.  Stack'  :: Stack  s a -> Basecase s a
  13.  
  14. data Stream s a = Stream (a,s)
  15.  
  16. data Linear s a = Linear (a,s) | End a
  17.  
  18. data Stack  s a = Stack  (a,s) | Empty
  19.  
  20. type family Head (xs :: [a]) :: a where
  21. Head (x ': xs) = x
  22.  
  23. type family All (f :: k -> Constraint) (xs :: [k]) :: Constraint where
  24.  All _ '[] = ()
  25. All f (x ': xs) = (f x,All f xs)
  26. {-
  27. data (All State xs) => Nested (xs :: [* -> * -> *]) (s :: *) (a :: *) where
  28.  Nested :: (State x,Head xs ~ x) => x s a -> Nested xs s a
  29. {-
  30.     No context is allowed on a GADT-style data declaration
  31.     (You can put a context on each constructor, though.)
  32.    |
  33. 27 | data (All State xs) => Nested (xs :: [* -> * -> *]) (s :: *) (a :: *) where
  34.    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
  35. -}
  36.  
  37. data (All State xs) => Nested (xs :: [* -> * -> *]) (s :: *) (a :: *) = Nested {unNested :: (State x,Head xs ~ x) => x s a}
  38.  
  39. {-
  40.    |
  41. 27 | data (All State xs) => Nested (xs :: [* -> * -> *]) (s :: *) (a :: *) = Nested {unNested :: (State x,Head xs ~ x) => x s a}
  42.    |                                                                                                                      ^
  43. -}
  44. -}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement