[Haskell-beginners] Functional Dependencies

Stephen Tetley stephen.tetley at gmail.com
Fri Dec 10 10:04:40 CET 2010


Hello Dan

What is /unflt/ ? I'm presuming it can't be unflatten [*] as I don't
see how it would work.

If I was making a flatten class, I wouldn't want Monad as a constraint
on the result container. Monad doesn't really say anything about
"containers" - there are some containers that are Monads, but there
are monads that aren't containers and there are containers that aren't
monads.

The Foldable type class in Data.Foldable is quite like a class for
flattenable things, however it folds (flattens) into a monoidal thing
(often called a "summary" value). This isn't so good for flattening
into a list. List has a monoid instance but it is very inefficient. If
you want to flatten into a list-like thing rather than fold into a
summary value, you would really need a better class something like
"Cons"

class Cons t where
  nil  :: t a
  cons :: a -> t a -> t a


By the way, there is no Monoid instance for Data.Tree at least at
version containers-0.3.0.0.


[*] If you are wanting unflatten as well, things get quite complicated...



More information about the Beginners mailing list