[Haskell-cafe] Re: Heterogeneous Data Structures - Nested Pairs and functional references

Alexander Solla ajs at 2piix.com
Sat Feb 20 19:04:20 EST 2010


On Feb 20, 2010, at 10:25 AM, Heinrich Apfelmus wrote:

> But isn't the line
>
>    renderXHtml (ConcatView l r) = fold $ renderXHtml (ConcatViews l r)
>
> a type error? I'm assuming
>
>    Data.Foldable.fold :: (Foldable m, Monoid t) => m t -> t
>
> being applied to the result type of  renderXHtml  which is  Html  and
> not of the form  m t .

Yup, that's a type error.  I mean to fold the View (in this case a  
ConcatView) into a monoid.  I think I meant

 > foldMap renderXHtml (ConcatViews l r)

> Your intention reminds me of the use of type variables to get
> functor-like behavior for free, like in
>
>    data RGB' a = RGB a a a   -- auxiliary type constructor
>    type RGB = RGB' Int       -- what we're interested in
>
> but I don't quite see what you're doing with the free monad here,  
> Alexander?

As you noticed, I am seeking that functorial behavior in order to gain  
some genericity.  bind and return do encode some logic about the  
nature of monadic adjunction, which I am relying on theoretically.  I  
could have used a Functor instance just as easily, but I would have  
lost my "intention" of defining co-equalizers implicitly.  (http://en.wikipedia.org/wiki/Beck%27s_monadicity_theorem 
)

Also, it was easier to write a monad instance than an Applicative  
instance, at least on my first try. ;-)


More information about the Haskell-Cafe mailing list