Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# Language MultiParamTypeClasses,FlexibleInstances,FlexibleContexts,FunctionalDependencies ,UndecidableInstances#-}
- newtype Safe s a = Safe {runSafe :: (a,Maybe s) }
- newtype Super s a = Super {runSuper :: (Maybe (a,Maybe s))}
- type SafeState s a = s -> Safe s a
- type SuperState s a = s -> Super s a
- type SuperNext s a = (a,s) -> (Maybe (a,Maybe s))
- class ExtraUnfoldable f g h | f h -> g, g h -> f where -- f g -> h,
- extraUnfoldr :: (s -> f s a) -> (s -> g s (h a))
- data Compose f g a = Compose (f (g a))
- instance (ExtraUnfoldable x y f,ExtraUnfoldable y z g) => ExtraUnfoldable x z (Compose f g) where
- -- exstraUnfoldr :: (ExtraUnfoldable f1 g h1, ExtraUnfoldable f2 f1 h2) => (s -> f2 s a) -> s -> g s (h1 (h2 a))
- exstraUnfoldr sf = extraUnfoldr (\s' -> extraUnfoldr sf s')
- -- where are the type level lambdas!?
- {- this all compiles;
- instance ExtraUnfoldable Super Safe [] where
- extraUnfoldr f s = Safe (hyloList f (:) [] s)
- where
- superStep :: SuperState s a -> (a -> b -> b) -> ((b,s) -> (Maybe (b,Maybe s)))
- superStep fs fa (b,s) = fmap (\(a,s') -> (fa a b,s')) (runSuper (fs s))
- hyloList :: SuperState s a -> (a -> b -> b) -> b -> (s -> (b,Maybe s))
- hyloList fs fa b s = go fs fa (b,Just s)
- where
- go :: SuperState s a -> (a -> b -> b) -> ((b,Maybe s) -> (b,Maybe s))
- go fs fa (b,ms) = maybe (b,ms) (go fs fa) (ms >>= \s -> superStep fs fa (b,s))
- data Tsnoc a b = Tsnoc b
- class ExtraUnfoldable (,) Tsnoc f => Unfoldable f
- instance ExtraUnfoldable (,) Tsnoc [] where
- extraUnfoldr sf s = let (s',x) = sf s
- Tsnoc xs = extraUnfoldr sf s'
- in Tsnoc (x : xs)
- instance Unfoldable []
- -}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement