Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# Language MultiParamTypeClasses,FlexibleInstances,FlexibleContexts,FunctionalDependencies ,UndecidableInstances#-}
  2.  
  3. newtype Safe  s a = Safe  {runSafe  ::        (a,Maybe s) }
  4. newtype Super s a = Super {runSuper :: (Maybe (a,Maybe s))}
  5.  
  6. type SafeState  s a = s -> Safe s a
  7. type SuperState s a = s -> Super s a
  8. type SuperNext  s a = (a,s) -> (Maybe (a,Maybe s))
  9.  
  10. class ExtraUnfoldable f g h | f h -> g, g h -> f where -- f g -> h,
  11.  extraUnfoldr :: (s -> f s a) -> (s -> g s (h a))
  12.  
  13. data Compose f g a = Compose (f (g a))
  14.  
  15. instance (ExtraUnfoldable x y f,ExtraUnfoldable y z g) => ExtraUnfoldable x z (Compose f g) where
  16. -- exstraUnfoldr :: (ExtraUnfoldable f1 g h1, ExtraUnfoldable f2 f1 h2) => (s -> f2 s a) -> s -> g s (h1 (h2 a))
  17.  exstraUnfoldr sf = extraUnfoldr (\s' -> extraUnfoldr sf s')
  18. -- where are the type level lambdas!?
  19.  
  20.  
  21. {- this all compiles;
  22. instance ExtraUnfoldable Super Safe [] where
  23.  extraUnfoldr f s = Safe (hyloList f (:) [] s)
  24.   where
  25.    superStep :: SuperState s a -> (a -> b -> b) -> ((b,s) -> (Maybe (b,Maybe s)))
  26.    superStep fs fa (b,s) = fmap (\(a,s') -> (fa a b,s')) (runSuper (fs s))
  27.    hyloList :: SuperState s a -> (a -> b -> b) -> b -> (s -> (b,Maybe s))
  28.    hyloList fs fa b s = go fs fa (b,Just s)
  29.     where
  30.      go :: SuperState s a -> (a -> b -> b) -> ((b,Maybe s) -> (b,Maybe s))  
  31.      go fs fa (b,ms) = maybe (b,ms) (go fs fa) (ms >>= \s -> superStep fs fa (b,s))
  32.  
  33. data Tsnoc a b = Tsnoc b
  34.  
  35. class ExtraUnfoldable (,) Tsnoc f => Unfoldable f
  36.  
  37. instance ExtraUnfoldable (,) Tsnoc [] where
  38.  extraUnfoldr sf s = let (s',x) = sf s  
  39.                          Tsnoc xs = extraUnfoldr sf s'
  40.                      in Tsnoc (x : xs)
  41.  
  42. instance Unfoldable []
  43. -}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement