public
Created

EnvT use case

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
import Data.Tree
import Control.Comonad
import Control.Comonad.Trans.Class
import Control.Comonad.Trans.Env
 
replusify:: MonadPlus m => [a] -> m a
replusify = msum . map return
 
class Treeish l where
children :: MonadPlus m => l -> m l
descendants :: MonadPlus m => l -> m l
 
instance Treeish (Tree a) where
children = replusify . subForest
descendants = replusify . flatten . duplicate
 
instance Treeish (EnvT e Tree a) where
children = replusify . map rootLabel . subForest . lower . duplicate
descendants = replusify . flatten . lower . duplicate

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.