When would you like to use OneTuple?

I just stumbled upon the OneTuple package on a hack. I want to know the goal, I'm sure that the author did not create it just for fun. So when can this be helpful? It is very clear what he is doing, but not when it can be used.

So, does anyone know any interesting examples when you can take advantage of this? Or maybe show mathematical beauty behind this?

+7
source share
4 answers

This is almost the same as the Identity monad, which is usually used as the base of the monad transformer stack, except that since OneTuple uses data instead of newtype , it has an additional lower value.

This is interesting because it is, in a sense, the most trivial example of most of the type classes that it implements. However, I do not see any practical use in this.

+3
source

Suppose you have a (slightly stupid) type that works with tuples. You have an instance for (a,a) , an instance for (a,a,a) . You need an instance for a single value. But you cannot just create an instance for a , because it will overlap with everything else! However, you can create an instance for OneTuple a .

Now that typeclass is a little useless, it’s easy to imagine a class similar to it, but more useful. In fact, this is just the use of Only in the mysql MySQL library: http://hackage.haskell.org/packages/archive/mysql-simple/0.2.0.2/doc/html/Database-MySQL-Simple-QueryResults.html

+4
source

This is certainly not a joke, just like the implementation of the monodar monad is not a joke. Unlike the simple type a you get all the useful instances, and you get an extra bottom that gives the singleton tuple much closer to the semantics of the other types of tuples.

One use case is the same as monad-identity, generalization. You have an applicative / monadic function that has the type of polymorphic functor. For example, many useful packages, such as enumerator support, work on the selected monad selected by the user. The slightly different OneTuple semantics (compared to Identity ) can be very useful when you have a complex data dependency or want to use extra laziness that Identity does not give you.

+3
source

I think this is something like a joke, for example not . However, OneTuple adds one new value to any type (unlike Maybe , which adds two: Nothing and either Just undefined or undefined depending on how your boat is rocking). So if you ever need it, you know where to go ...

+2
source

All Articles