[ANN] anonymous-sums

Someone once wondered why there are no anonymous sum types in Haskell: https://groups.google.com/forum/#!topic/haskell-cafe/cIxfLdcJ7aI Wonder no more: http://hackage.haskell.org/package/anonymous-sums Occasionally I have needed this so I split it off into a package. If there is already something like this out there (or some elegant way to do this that doesn't involve hairy extensions), please let me know and I will be all too happy to deprecate this. Omari

On Thu, Feb 13, 2014 at 4:36 PM, Omari Norman
If there is already something like this out there (or some elegant way to do this that doesn't involve hairy extensions), please let me know and I will be all too happy to deprecate this.
Omari
Hi Omari, You could use: type S3 a b c = (Maybe a, Maybe b, Maybe c) And then prove to yourself that only one entry is Just. This lets you use of classes that work with tuples such as Field1 through Field9 from lens or things from http://hackage.haskell.org/package/tuple. At least that's the strategy in < http://hackage.haskell.org/package/HList-0.3.2.0/docs/Data-HList-Variant.htm...
.
Regards, Adam

* adam vogt
On Thu, Feb 13, 2014 at 4:36 PM, Omari Norman
wrote: If there is already something like this out there (or some elegant way to do this that doesn't involve hairy extensions), please let me know and I will be all too happy to deprecate this.
Omari
Hi Omari,
You could use:
type S3 a b c = (Maybe a, Maybe b, Maybe c)
And then prove to yourself that only one entry is Just. This lets you use of classes that work with tuples such as Field1 through Field9 from lens or things from http://hackage.haskell.org/package/tuple.
At least that's the strategy in < http://hackage.haskell.org/package/HList-0.3.2.0/docs/Data-HList-Variant.htm...
.
Yes, this solution is highly recommended... by @EvilHaskellTips :-) https://twitter.com/EvilHaskellTips/status/433403451054096384 Roman

NOOOO! Why would you stop at S15, I really really need S17!
14.02.2014, 01:36, "Omari Norman"
Someone once wondered why there are no anonymous sum types in Haskell:
https://groups.google.com/forum/#!topic/haskell-cafe/cIxfLdcJ7aI
Wonder no more:
http://hackage.haskell.org/package/anonymous-sums
Occasionally I have needed this so I split it off into a package.
If there is already something like this out there (or some elegant way to do this that doesn't involve hairy extensions), please let me know and I will be all too happy to deprecate this.
Omari _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi, Omari Norman wrote:
What about S0 and S1? Tillmann

Yeah, S0 and S1 are probably worth including for the sake of completion. We don't have a 1-tuple, and I believe that's caused a bit of trouble for people writing generic libraries. Enough trouble so that somebody wrote a OneTuple package[1] anyhow. Of course, S0 is isomorphic to Void and S1 is isomorphic to Identity, but I don't think that's a big deal especially given that S2 is isomorphic to Either. [1]: http://hackage.haskell.org/package/OneTuple-0.2.1/docs/Data-Tuple-OneTuple.h... On Fri, Feb 14, 2014 at 3:38 PM, Tillmann Rendel < rendel@informatik.uni-marburg.de> wrote:
Hi,
Omari Norman wrote:
What about S0 and S1?
Tillmann
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Fri, Feb 14, 2014 at 11:02 PM, Tikhon Jelvis
Yeah, S0 and S1 are probably worth including for the sake of completion. We don't have a 1-tuple, and I believe that's caused a bit of trouble for people writing generic libraries. Enough trouble so that somebody wrote a OneTuple package[1] anyhow.
S1 is easy enough; I added that in. http://hackage.haskell.org/package/anonymous-sums-0.2.2.0 S0 takes some more thought as there's more than one way to do that. I could use EmptyDataDecls or do it more like ekmett's Data.Void. Then what do you get for, e.g., partitionS0? partitionS0 :: [S0] -> () I suppose that makes sense if you look at partition as returning the same number of lists as there are type variables. No type variables, no lists. Or should it be partitionS0 :: [S0] -> Void which also makes me wonder if this is a special case better left to Data.Void. Thoughts?

* Omari Norman
On Fri, Feb 14, 2014 at 11:02 PM, Tikhon Jelvis
wrote: Yeah, S0 and S1 are probably worth including for the sake of completion. We don't have a 1-tuple, and I believe that's caused a bit of trouble for people writing generic libraries. Enough trouble so that somebody wrote a OneTuple package[1] anyhow.
S1 is easy enough; I added that in.
http://hackage.haskell.org/package/anonymous-sums-0.2.2.0
S0 takes some more thought as there's more than one way to do that. I could use EmptyDataDecls or do it more like ekmett's Data.Void. Then what do you get for, e.g., partitionS0?
partitionS0 :: [S0] -> ()
I suppose that makes sense if you look at partition as returning the same number of lists as there are type variables. No type variables, no lists. Or should it be
partitionS0 :: [S0] -> Void
which also makes me wonder if this is a special case better left to Data.Void.
The result should be a 0-tuple, i.e. (), of course. Otherwise, what would paritionS0 [] return? Roman

On Sat, Feb 15, 2014 at 9:08 AM, Roman Cheplyaka
partitionS0 :: [S0] -> ()
I suppose that makes sense if you look at partition as returning the same number of lists as there are type variables. No type variables, no lists. Or should it be
partitionS0 :: [S0] -> Void
which also makes me wonder if this is a special case better left to Data.Void.
The result should be a 0-tuple, i.e. (), of course.
Otherwise, what would paritionS0 [] return?
OK, so with EmptyDataDecls this yields: data S0 deriving (Generic, Typeable) instance Eq S0 where _ == _ = undefined instance Ord S0 where compare _ _ = undefined instance Read S0 where readsPrec _ = undefined instance Show S0 where show _ = undefined partitionS0 :: [S0] -> () partitionS0 _ = () caseS0 :: S0 -> z caseS0 = undefined mapS0 :: S0 -> S0 mapS0 = id mapS0f :: Functor ftr => S0 -> ftr S0 mapS0f = undefined
participants (6)
-
adam vogt
-
Miguel Mitrofanov
-
Omari Norman
-
Roman Cheplyaka
-
Tikhon Jelvis
-
Tillmann Rendel