haskell,monad-transformers,state-monad,free-monad

Look at the type signature for runTest: it returns a value in a monad m as long as m is a MonadState FakeDB. So when you call runTest you need to bind it into such a monad, which IO is not (that's what the error message is telling you). Try...

scala,functional-programming,functor,free-monad

Hopefully I can answer your question: Do Free monads compose? No. For the same reasons as "normal" monads don't. To write monadic bind we need to know something about the underlying monad, or about the underlying functor in a free monad case. Hopefully the Haskell syntax doesn't scare you too...

scala,functional-programming,rss,free-monad

Not really, because XML isn't an interpretation; it's a data structure, it has denotational rather than just operational semantics[1]. So you can define your primitives, and have a tree of them, and transform that pure tree to... another pure tree representing the XML. There's no need for the monad, this...

haskell,abstract-syntax-tree,free-monad

Make it simple You can simplify the last two lines into. newtype Term α = T {unT :: Free (TermF Term) α} This should help you know to consistently use T and unT everywhere instead of only at every other level. Make it complicated Both Free and TermF have the...

Types It sounds like you might be looking for the composition of functors, which lives in the transformers package in Data.Functor.Compose: newtype Compose f g a = Compose { getCompose :: f (g a) } If I understand your two questions correctly, you want to add things before and after...

This is a relatively well-known limitation of open sums "à la Carte". In short, if we have an f functor that itself has one or more inner type indices, then type inference suffers significantly for open sums containing that functor. Illustrating the reasons, suppose we have an open sum that...

haskell,abstract-syntax-tree,free-monad

Here's my take using syb (as mentioned on Reddit): {-# LANGUAGE LambdaCase #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE DeriveDataTypeable #-} module Main where import Prelude hiding (repeat) import Data.Data import Control.Monad (forM_) import Control.Monad.Free import Control.Monad.Free.TH import Data.Generics (everywhere, mkT) data...