This prints 5. Note that I require the sets to be order-insensitive, since that's the point of what I'm saying. How would you accomplish this simple task in Haskell? I haven't been able to determine *any* way so far, but I would love to find a way. I'll have a look at the library again (it's been a *long* time), but if you find a way first, let me know.
Name:
markvangulik2015-02-20 22:32
Ok, I've looked through Data.Set. It looks like it should work just fine for the tiny category of homogenous element types that have a natural full order. And Eq converts the sets to lists to compare them with Eq. That's probably about as well as can be done in Haskell, and it's probably even reasonably efficient for a lazy language (i.e., it can give up early on unequal sets if one of the leftmost elements ("small" in the "<" sense) differs.
It looks like Map is about the same, although I couldn't figure out if it has an equality operation.
Now back to my statement. Can Haskell have a map from sets to integers? Nope. Set doesn't define an ordering operation (between Sets), so it's not allowed as the key of a Map. In Avail, *anything* can be a member of a Set. And *anything* can be the key of a Map.
As for (2), I decided to conflate the traditional notion of heterogenous tuples with homogenous lists. At first I was concerned that it might not be a good fit, and I remained ready to split the concepts, but after a while I saw that it actually worked out wonderfully. It even has a beautiful stack-like emergent property at the left end. I been fooled around with a typed Joy "implementation" in Avail. Prepending a constant number of things onto the left of a tuple preserves the detailed type information of the tuple's element types, so I treated the left end of a tuple as the Joy operand stack.
(3) Since Set can't be a key in a Map, please indicate how I would produce a KeyableSet that's a subtype of Set. It's more than a little tricky to add subtyping to a language that effectively only operates on partially-evaluated expressions. Maybe not completely impossible, but so far I'm unaware of any way it could work. It's unlikely to be doable by adding more tags.
Likewise, exceptions are a concept tied intimately to control flow, which Haskell doesn't have. For them to be useful they must indicate the failure of some operation, not the production of an unexpected result. Perhaps there may be something that subsumes them in the lazy evaluation world, but I sure haven't seen it.