[Haskell-cafe] Re: Typeclass vs. Prolog programming

2006-09-30 Thread oleg

I previously wrote:
 The typechecker commits to the instance
 and adds to the current constraints
 TypeCast x Int, Ord Bool, Eq Bool
 The latter two are obviously satisfied and so discharged. The former
 leads to the substitution {x-Int}.

I should have been more precise and said: 
The former _eventually_ leads to the substitution {x-Int}.

Your analysis is right on the mark. That's exactly how I think of
TypeCast.


 This is all very beautiful, but it's a little annoying that the
 cornerstone silver bullet TypeCast has to be defined in a way that
 fools the typechecker into doing the right thing in spite of itself.

One of the drafts of the HList paper, when describing TypeCast,
literally had a phrase about `fooling the typechecker'...

Well, it seems things like TypeCast were not envisioned by the
Founding Fathers. In this respect, the story of C++ templates come to
mind. My feeling is that we're still discovering the capabilities of
the Haskell typechecker and the right abstractions. We should view
TypeCast as an ungainly _encoding_ of a simple abstraction, or just as
a tool for implementing type-level typecase and local improvement
rules. When the right abstraction emerges (and perhaps it already has:
CHR), GHC might implement it directly. Until then, we can use the
encoding...

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Typeclass vs. Prolog programming

2006-09-28 Thread Jason Dagit

On 9/27/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:


This message is intended as a long answer to Michael Shulman's
question (Re: variadic functions and typeCast) and Jason Dagit's
question (Re: Duplicate Instance problem). Incidentally, the short
answer to Jason Dagit's question is `constraints are disregarded
during instance selection'. The answer to Michael Shulman is yes.


Hmm...Perhaps I'm just sleepy but I read through the descriptions
below and I'm still not sure if what I want to do is easy or extremely
difficult.  I think you're suggesting that I should use something like
TypeCast to control the unification if I want to get rid of my
duplicate instances problem?

I'll re-read this a few times and look at the TypeCast stuff.  I feel
like this is quite a bit over my head at the moment, but your
description is very good and hopefully it will make more sense in the
morning.

Thanks,
Jason
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Typeclass vs. Prolog programming

2006-09-28 Thread Michael Shulman

Thank you Oleg!  That explanation is very clear.

On 9/28/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

The typechecker commits to the instance
and adds to the current constraints
TypeCast x Int, Ord Bool, Eq Bool
The latter two are obviously satisfied and so discharged. The former
leads to the substitution {x-Int}.


By the rules just enumerated, this substitution would be forbidden,
since the type variable x is not considered variable, right?  So this
happens via the magic of functional dependencies?  The typechecker
encounters (eventually) the instance

instance TypeCast'' () x x

and since TypeCast'' is declared with a functional dependency:

class TypeCast'' t x y | t x - y, t y - x

it concludes that the first x in the above instance is uniquely
determined by the second, which in our case is Int, and therefore x
must be Int.  Is that right?

This is all very beautiful, but it's a little annoying that the
cornerstone silver bullet TypeCast has to be defined in a way that
fools the typechecker into doing the right thing in spite of itself.
Is this all part of the general fundeps are very hard to get right
problem?

Mike
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe