Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm not 100% sure of what the author had in mind, but here's a possible (and possibly dumb) example.

Imagine you need a 2-parameter "Lasagna" datatype wich is a non-empty list of alternating "a" and "b" elements. It could be used to model something like a timeline, perhaps.

Instead of constructing it by hand, you could express it as a composition of other stuff:

    import Data.List.NonEmpty
    import Data.Bifunctor
    import Data.Bifunctor.Tannen

    type Lasagna = Tannen NonEmpty (,)

    example :: Lasagna Char Int
    example = Tannen $ ('a',3) :| [('b',4),('d',6)]
http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-L...

https://hackage.haskell.org/package/bifunctors-5.4.2/docs/Da...

That type has a whole bunch of useful instances without even having to auto-derive them.

And you could have functions that manipulated the pairs without caring what shape the "outer functor" has.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: