Generalization of Named
I introduced the
Named data in my last article, and I tried to generalize a bit.
I came to the
Civility idea and more, the
Citizen data. They are some information that define an object in a context, but does not define entirely it (like a
Name: it identify yourself as a citizen, but not has a Human being). So a
Citizen is something with its papers:
But that is likely a tuple, and in fact, all the previous instances are correctly defined for Tuples!
So in-fine we have
More results than the ones on the previous-Named ?
Monads and CoMonads together ?
Some pretty results are coming if the papers are an instance of a
Monoid: We have
Theses samples of code are took from http://hackage.haskell.org/package/base-184.108.40.206/docs/src/GHC.Base.html#line-433
Basically, if there are empty papers and a way to concatenate them,
Citizen become a
Yes, you apply a function independently on papers and on the object, so you are also wining a
Utility: The Grouped example:
Grouped is a common data:
You can find it in the
Weigh package. It represents a kind of Rose Tree.
You can write a pretty function that transform the structure in a “after-parsing” one:
Now imagine you have a
tree :: Grouped (Named File) representing a file tree in a Unix system
Then you have:
>>> printTree $ Group "" [Simple (withName "info.txt" ()), Group "bin" [Simple (withName "ghc" ()),Simple (withName "stack" ())]] /info.txt /bin/ghc /bin/stack