On 7/31/07, jeff p &lt;<a href="mailto:mutjida@gmail.com">mutjida@gmail.com</a>&gt; wrote:<br><br>&gt; Hello,<br><br>&gt; &gt; My understanding is that this sort of instance collection doesn&#39;t<br>&gt; &gt; work together because instance selection is based only on the
<br>&gt; &gt; matching the head of an instance declaration (part after the<br>&gt; &gt; &quot;=&gt;&quot;).&nbsp; I&#39;m wondering why not use the preconditions as well, via a<br>&gt; &gt; Prolog-like, backward-chaining search for much more flexible
<br>&gt; &gt; instance selection?&nbsp; Going further, has anyone investigated using<br>&gt; &gt; Prolog as a model for instance selection?<br><br>&gt; I have also wanted more powerful, Prolog-like search for instance<br>&gt; selection; it would be particularly convenient to think of type
<br>&gt; variables as logic variables.<br><br>&gt; I think the main argument against this is that it fundamentally<br>&gt; changes the interpretation of constraints; in particular, if you<br>&gt; really used a Prolog-style search, the order in which you place
<br>&gt; constraints can affect type checking. Is there a sensible way for<br>&gt; instance selection to depend on the &quot;body&quot; which doesn&#39;t result in<br>&gt; this?<br><br>How could constraint order affect type checking?&nbsp; Via &quot;cut&quot; (&quot;!&quot;)?&nbsp; I&#39;d omit cut.&nbsp; I see how order of constraints or instance declarations might determine order of solutions produced (as in Prolog).&nbsp; If the compiler rejects ambiguity (existence of multiple solutions), then I&#39;d wouldn&#39;t expect the order to have any visible effect.
<br><br>&gt; &gt; Better yet, how about LambdaProlog (<br>&gt; &gt; <a href="http://www.lix.polytechnique.fr/Labo/Dale.Miller/lProlog">http://www.lix.polytechnique.fr/Labo/Dale.Miller/lProlog</a>), which<br>&gt; &gt; generalizes from Horn clauses to (higher-order) hereditary Harrop
<br>&gt; &gt; formulas, including (restricted but powerful) universals,<br>&gt; &gt; implication, and existentials?<br><br>&gt; Having hereditary Harrop formulas at the type level would be<br>&gt; cool. It would also probably require type level lambdas.
<br><br>Type level lambdas may not be necessary for HHFs.&nbsp; For simplicity, LambdaProlog encodes its universals and existentials via lambdas.&nbsp; I think we could use type lambdas if we wanted but wouldn&#39;t have to.<br><br>
Personally, I&#39;d like to have type level lambdas, assuming we can implement them soundly.<br><br>&gt; There was a recent discussion about type level lambdas in Haskell<br>&gt; which ended with the observations that 1) it would mess up
<br>&gt; unification (i.e. make it undecidable and/or too hard) to have<br>&gt; explicit type level lambdas; and 2) they are already implicitly<br>&gt; there (this was pointed out by Oleg) since one can define a type<br>&gt; level application and type level functions. I think 1) is a bit of a
<br>&gt; cop-out since you could always restrict to pattern unification<br>&gt; (L-lamda unification) which is decidable and has MGUs. 2) is true,<br>&gt; but these implicit lambdas don&#39;t play very well with instance<br>
&gt; selection and require that all reductions are spelled out via an<br>&gt; Apply type class.<br><br>&gt; I think it might be useful/interesting to have type level lambdas,<br>&gt; and pattern unification, even without turning instance selection
<br>&gt; into proof search.<br><br>Agreed.&nbsp; And vice versa.<br><br>&gt; &gt; Once search is in there, ambiguity can arise, but perhaps the<br>&gt; &gt; compiler could signal an error in that case ( i.e., if the<br>&gt; &gt; ambiguity is not eliminated by further search pruning).
<br><br>&gt; This seems like a slippery slope to me.<br><br>&gt; Although I would like having a full fledged (higher-order) logic<br>&gt; programming language in which to write type level programs, I am not<br>&gt; sure it&#39;s a good idea for Haskell in general. I tend to get
<br>&gt; concerned when type class constraints get too big/complicated to be<br>&gt; obviously correct-- what good is the type checker saying something<br>&gt; satisfies a constraint if we&#39;re not sure that the specification of
<br>&gt; the constraint itself is correct?<br><br>&gt; -Jeff<br><br>I like this goal of and motivation for simplicity in type specifications.&nbsp; My hope is that a Lambda-Prolog (or some such, and minus cut) would provide a simpler (and more expressive) basis than the very tricky encodings available now (type level function application, backtracking with type-level numeral annotations, etc).
<br><br>&nbsp; - Conal