Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Created February 16, 2013 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danidiaz/4967054 to your computer and use it in GitHub Desktop.
Save danidiaz/4967054 to your computer and use it in GitHub Desktop.
EnvT use case
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment