Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# Language
  2. Rank2Types,
  3. PolyKinds,
  4. TypeFamilies,
  5. DatatypeContexts,
  6. MultiParamTypeClasses,
  7. UndecidableInstances,
  8. UndecidableSuperClasses
  9. #-}
  10.  
  11.  
  12. import GHC.Exts
  13.  
  14. {-
  15. type family State (x :: * -> * -> *) :: Constraint where
  16.  State Basecase = ()
  17.  State (Nested xs) = ()
  18.  
  19. data Basecase s a where
  20.  Stream' :: Stream s a -> Basecase s a
  21.  Linear' :: Linear s a -> Basecase s a
  22.  Stack'  :: Stack  s a -> Basecase s a
  23.  
  24. this was the original definition of "Base"
  25. however, having converted it to a type family emulating a "closed class" below
  26. it can no longer be matched over as in the type family State above.
  27. how can this process work in a way that retains this ability?
  28. we cannot match over constraints...
  29. -}
  30.  
  31. data Stream s a = Stream (a,s)
  32.  
  33. data Linear s a = Linear (a,s) | End a
  34.  
  35. data Stack  s a = Stack  (a,s) | Empty
  36.  
  37. type family Base (b :: * -> * -> *) :: Constraint where
  38.  Base Stream = ()
  39.  Base Linear = ()
  40.  Base Stack  = ()
  41.  
  42. class Base (FlatBase f) => Flat f where -- not considering Nested Base functors yet, so no Trees etc
  43.  type FlatBase f :: * -> * -> *
  44.  
  45. type State b s a = Base b => s -> b s a
  46.  
  47. type CoState b s a = Base b => b s a -> s
  48.  
  49. class Flat f => Get f where
  50.  get :: CoState (FlatBase f) (f a) a
  51.  
  52. class Flat f => Set f where
  53.  set :: State (FlatBase f) (f a) a
  54.  
  55. data (Get f,Set f) => Zipper f a = Zipper [a] (f a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement