
OK, so if you do something like class Container c where type Element c :: * then we now have a clean and concise way to discover what type of element any given container holds. (Regardless of whether it's element type is parametric, hard-coded, class-constrained or anything else.) I really like this! Now suppose that instead of a container type with an associated element type, what we want is several pairs of types having a one-to-one relationship, and we want to be able to traverse that relationship in either direction. What's the best way to do that? (I tried just having two mirror image classes like the one above. But that doesn't work; there's no guarantee that going one way and then going back the other way will definitely take you back to where you started. I tried to make that a constraint, and got an error message that basically says "this feature is not implemented". Great. Still, there's probably a better way to do this.)

On 03.08.2010 21:25, Andrew Coppin wrote:
Now suppose that instead of a container type with an associated element type, what we want is several pairs of types having a one-to-one relationship, and we want to be able to traverse that relationship in either direction. What's the best way to do that?
(I tried just having two mirror image classes like the one above. But that doesn't work; there's no guarantee that going one way and then going back the other way will definitely take you back to where you started. I tried to make that a constraint, and got an error message that basically says "this feature is not implemented". Great. Still, there's probably a better way to do this.)
That's possible with multiparameter type classes and fundeps. Without any further words I'm pasting code snippet:
class Relator a b | a -> b, b -> a where to :: a -> b from :: b -> a
data Knight = Knight deriving Show data Dragon = Dragon deriving Show
instance Relator Knight Dragon where to _ = Dragon from _ = Knight
I'm not sure that it's what you want.

So I believe the "final" way to do this, which is not yet implemented,
works something like this:
type family LeftToRight a
type family RightToLeft b
class (LeftToRight a ~ b, RightToLeft b ~ a) => Bijection a b where
...
I agree, the fact that this doesn't work is really dumb.
I used a slightly devious trick to solve this for Control.Coroutine[1]:
type family Dual a
-- what I wanted to write:
class (s ~ Dual (Dual s)) => Connect s where
connect :: Session s a -> Session (Dual s) b -> (a,b)
-- what I actually wrote
class Connect s where
connect :: (s ~ Dual (Dual s)) => Session s a -> Session (Dual s) b -> (a,b)
This was good enough to give the constraints I needed to implement
"connect" for each of the session operators.
-- ryan
[1] http://hackage.haskell.org/packages/archive/Coroutine/0.1.0.0/doc/html/Contr...
On Tue, Aug 3, 2010 at 10:25 AM, Andrew Coppin
OK, so if you do something like
class Container c where type Element c :: *
then we now have a clean and concise way to discover what type of element any given container holds. (Regardless of whether it's element type is parametric, hard-coded, class-constrained or anything else.) I really like this!
Now suppose that instead of a container type with an associated element type, what we want is several pairs of types having a one-to-one relationship, and we want to be able to traverse that relationship in either direction. What's the best way to do that?
(I tried just having two mirror image classes like the one above. But that doesn't work; there's no guarantee that going one way and then going back the other way will definitely take you back to where you started. I tried to make that a constraint, and got an error message that basically says "this feature is not implemented". Great. Still, there's probably a better way to do this.)
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Tue, Aug 3, 2010 at 9:45 PM, Ryan Ingram
So I believe the "final" way to do this, which is not yet implemented, works something like this:
type family LeftToRight a type family RightToLeft b
class (LeftToRight a ~ b, RightToLeft b ~ a) => Bijection a b where ...
I agree, the fact that this doesn't work is really dumb.
I think it is more simple like: class Bijection a b where ... type LeftToRight a = (Bijection a b) => b type RightToLeft b = (Bijection a b) => a -- Victor Nazarov

On 4 August 2010 03:45, Ryan Ingram
So I believe the "final" way to do this, which is not yet implemented, works something like this:
type family LeftToRight a type family RightToLeft b
class (LeftToRight a ~ b, RightToLeft b ~ a) => Bijection a b where ...
I agree, the fact that this doesn't work is really dumb.
The reason Manuel Chakravarty gave me (if I recall correctly) that this doesn't work is as follows: Type classes are stored in dictionaries. To be able to have superclass constraints like this requires that type information also be stored in those dictionaries, which currently isn't done. They could have added this functionality in, but SPJ was going to be working on a new type-checker anyway (which I believe is now done) so this was postponed until after the new type-checker was finished. As we should hopefully be seeing 6.14 out in a few months time, there isn't time to be able to get superclass constraints in for it, so we probably won't have them until 6.16 next year. So, I wouldn't say that it's "dumb". Unfortunate, a pity, etc., but not "dumb". Don't forget, GHC is open source: if this lack really was "dumb" and annoying you, there was nothing stopping you from rectifying this situation up until now. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

Ivan Lazar Miljenovic wrote:
Don't forget, GHC is open source: if this lack really was "dumb" and annoying you, there was nothing stopping you from rectifying this situation up until now.
Except that, in the real world, this is actually completely infeasible. Yes, I know it's the basic tenant of OSS that you can modify the program to do whatever you want. But in reality, something like GHC is far too large and complex for this to be a realistic possibility. And this holds for most other nontrivial software too.

Ivan Lazar Miljenovic wrote:
Don't forget, GHC is open source: if this lack really was "dumb" and annoying you, there was nothing stopping you from rectifying this situation up until now.
Except that, in the real world, this is actually completely infeasible. Yes, I know it's the basic tenant of OSS that you can modify the program to do whatever you want. But in reality, something like GHC is far too large and complex for this to be a realistic possibility. And this holds for most other nontrivial software too.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe Fair enough, but if one can't do better one's self then one should be careful about calling the work of others "dumb", which was the original
On 8/4/10 11:40 PM, Andrew Coppin wrote: point. Cheers, Greg

On 5 August 2010 16:48, Gregory Crosswhite
On 8/4/10 11:40 PM, Andrew Coppin wrote:
Ivan Lazar Miljenovic wrote:
Don't forget, GHC is open source: if this lack really was "dumb" and annoying you, there was nothing stopping you from rectifying this situation up until now.
Except that, in the real world, this is actually completely infeasible. Yes, I know it's the basic tenant of OSS that you can modify the program to do whatever you want. But in reality, something like GHC is far too large and complex for this to be a realistic possibility. And this holds for most other nontrivial software too.
Fair enough, but if one can't do better one's self then one should be careful about calling the work of others "dumb", which was the original point.
Exactly. Either do it yourself or be grateful that someone has done _something_, even if it isn't as good as you like. It's not like you're paying for it... -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

Ivan Lazar Miljenovic wrote:
On 5 August 2010 16:48, Gregory Crosswhite
wrote: On 8/4/10 11:40 PM, Andrew Coppin wrote:
Ivan Lazar Miljenovic wrote:
Don't forget, GHC is open source: if this lack really was "dumb" and annoying you, there was nothing stopping you from rectifying this situation up until now.
Except that, in the real world, this is actually completely infeasible. Yes, I know it's the basic tenant of OSS that you can modify the program to do whatever you want. But in reality, something like GHC is far too large and complex for this to be a realistic possibility. And this holds for most other nontrivial software too.
Fair enough, but if one can't do better one's self then one should be careful about calling the work of others "dumb", which was the original point.
Exactly. Either do it yourself or be grateful that someone has done _something_, even if it isn't as good as you like. It's not like you're paying for it...
Well *I* didn't say that anything was dumb. I was merely pointing out that the much-touched "do it yourself" benefit of OSS is actually out of most people's reach. There surely can't be many people alive on Earth who actually understand type theory, and far fewer who understand it well enough to meddle with something as astonishingly complex as GHC. So really, there's little or no chance of anybody except the GHC devs fixing this. (If nothing else, the learning curve is pretty much vertical just to fix this one minor problem.) On the one hand, it's nice that we have a freely available compiler at all. (And it's one of the best pieces of Haskell software I've seen to date.) On the other hand, I've seen too many people who write open-source software answer every query and issue simply with "patches welcome". As if that's a magic bullet to solve every problem and deficiency. There needs to be a reasonable balance. (Note that in the particular case of GHC, I think us users are getting a pretty good deal. My statements are about open-source in general, not about GHC.)

Andrew Coppin
Well *I* didn't say that anything was dumb. I was merely pointing out that the much-touched "do it yourself" benefit of OSS is actually out of most people's reach. There surely can't be many people alive on Earth who actually understand type theory, and far fewer who understand it well enough to meddle with something as astonishingly complex as GHC. So really, there's little or no chance of anybody except the GHC devs fixing this. (If nothing else, the learning curve is pretty much vertical just to fix this one minor problem.)
Yes, but on the other hand people shouldn't complain that said clever devs haven't done something if they're not smart enough to know if it's possible to do so or not.
On the one hand, it's nice that we have a freely available compiler at all. (And it's one of the best pieces of Haskell software I've seen to date.) On the other hand, I've seen too many people who write open-source software answer every query and issue simply with "patches welcome". As if that's a magic bullet to solve every problem and deficiency. There needs to be a reasonable balance.
Well, if I write software for free as a hobby and you want some feature added to my package which doesn't interest me enough to write myself (or I don't have time to do so), then if you really want it why don't you write it yourself? I think the best and most polished package I'm responsible for is graphviz, and I started off with that by submitting a patch to Matthew Sackman to add clustering support to it because I wanted such support. Of course, people might not be able to add such functionality themselves because they don't know how to do so (and even just saying "patches welcome" on its lonesome is a bit rude/blunt), but I have no problem with asking people to assist in developing a feature they really want to something I maintain (the record label support now in graphviz is kind of a case in point: someone asked me if I could add it in, I said I was busy to do so at the time but offered to help them how to do so and sketched out how to do so; in the end they weren't able to do so and when I had time I added it in). TL;DR: just because a library is freely available doesn't mean the maintainer will go and willingly implement every single little feature you want for no reason. It's a two-way street. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

On Wed, Aug 4, 2010 at 11:55 PM, Ivan Lazar Miljenovic
On 5 August 2010 16:48, Gregory Crosswhite
wrote: On 8/4/10 11:40 PM, Andrew Coppin wrote:
Ivan Lazar Miljenovic wrote:
Don't forget, GHC is open source: if this lack really was "dumb" and annoying you, there was nothing stopping you from rectifying this situation up until now.
Except that, in the real world, this is actually completely infeasible. Yes, I know it's the basic tenant of OSS that you can modify the program to do whatever you want. But in reality, something like GHC is far too large and complex for this to be a realistic possibility. And this holds for most other nontrivial software too.
Fair enough, but if one can't do better one's self then one should be careful about calling the work of others "dumb", which was the original point.
Exactly. Either do it yourself or be grateful that someone has done _something_, even if it isn't as good as you like. It's not like you're paying for it...
My bad, no offense was meant, and perhaps I should choose my words better. I've read Manuel's papers and worked with Simon, and they're both very smart people. I wasn't commenting at all on the quality of their implementation, but rather trying to make the point that it's really a bug that it doesn't work, and, AFAIK, a bug that is going to be fixed. I think everyone can relate to the frustration that occurs when you are surprised by a feature being missing. I actually think it's a testament to the quality of GHC that things "just work" so often that I can be so surprised when they don't. -- ryan

On Thu, Aug 5, 2010 at 7:18 AM, Ryan Ingram
I actually think it's a testament to the quality of GHC that things "just work" so often that I can be so surprised when they don't.
Well said. That's the feeling most Haskellers have, and that's part of the awesomeness of programming with Haskell. Cheers! -- Felipe.
participants (7)
-
Alexey Khudyakov
-
Andrew Coppin
-
Felipe Lessa
-
Gregory Crosswhite
-
Ivan Lazar Miljenovic
-
Ryan Ingram
-
Victor Nazarov