Oleg,<br><br>Many thanks for your help! i notice that the code you sent requires -fglasgow-exts to be syntactically correct. Is there documentation on the multi-parameter type classes? i think i see what you&#39;ve done, but i&#39;d like to read up on it to make sure that i understand.
<br><br>Best wishes,<br><br>--greg<br><br><div><span class="gmail_quote">On 4/20/07, <b class="gmail_sendername"><a href="mailto:oleg@pobox.com">oleg@pobox.com</a></b> &lt;<a href="mailto:oleg@pobox.com">oleg@pobox.com</a>
&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>Greg Meredith wrote:<br>&gt; The file compiles with ghc as is. If you uncomment the last
<br>&gt; section, however, you see that to close the loop on the constraints for the<br>&gt; agent syntax we hit a typing error. i &lt;b&gt;&lt;i&gt;think&lt;/i&gt;&lt;/b&gt; this is a hard<br>&gt; constraint in Haskell that prevents this level of generality in the
<br>&gt; specification, but maybe you can see a way around it.<br><br>I believe the Haskell typechecker is right<br><br>&gt; instance (Eq n, Eq p) =&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CoreAgentSyntax (MinimalAgentSyntax n p) where<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bind [] proc = Thunk (\() -&gt; proc)
<br>&gt;<br>&gt; data MinimalAgentSyntax n p =<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thunk (() -&gt; p)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Abstraction ([n] -&gt; p)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Concretion [n] p<br><br>The bind method has the signature<br><br>&nbsp;&nbsp;&nbsp;&nbsp;bind :: (CoreProcessSyntax p, CoreAgentSyntax x) =&gt; [n] -&gt; (p a x) -&gt; x
<br><br>That is: for any agent x and for _any_ process p (regardless of x), we<br>should be able to perform the bind operation. The signature for bind<br>proclaims total independence between &#39;p&#39; and &#39;x&#39;. However, when we
<br>define the instance<br><br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CoreAgentSyntax (MinimalAgentSyntax n p) where<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bind [] proc = Thunk (\() -&gt; proc)<br><br>we see that process proc and the agent aren&#39;t totally independent: the
<br>result of bind has the type &#39;MinimalAgentSyntax n process&#39; and thus is<br>dependent on the &#39;process == p a x&#39;. We have broken our previously<br>made independence proclamation, and so the typechecker rightfully
<br>complaints.<br><br>The following is one solution. It works sans the line marked TODO. I&#39;m<br>not sure that line is correct:<br><br>--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- TODO : lgm : need to substitute m for n in proc<br>--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bind (name:names) proc = Abstraction (\m -&gt; bind names proc)
<br><br>According to the type of Abstraction, &#39;bind names proc&#39; should have<br>the type &#39;p&#39;, that is, the same type as proc. It should be a<br>process. OTH, bind returns an agent. Something is amiss here.<br>
<br><br>{-# OPTIONS -fglasgow-exts #-}<br><br>module Core where<br><br>-- What&#39;s in a name?<br><br>class Nominal n where<br>&nbsp;&nbsp;&nbsp;&nbsp;nominate :: i -&gt; n i<br><br>newtype Name i = Nominate i deriving Eq<br><br>instance Nominal Name where nominate i = Nominate i
<br><br>-- Where are we?<br><br>class Locality a where<br>&nbsp;&nbsp;&nbsp;&nbsp;locate :: (Eq s, Nominal n) =&gt; s -&gt; (n i) -&gt; a s (n i)<br>&nbsp;&nbsp;&nbsp;&nbsp;name :: (Eq s, Nominal n) =&gt; a s (n i) -&gt; (n i)<br><br>data Location s n = Locate s n deriving Eq
<br><br>instance Locality Location where<br>&nbsp;&nbsp; locate s n = Locate s n<br>&nbsp;&nbsp; name (Locate s n) = n<br><br><br>-- Constraints<br><br>class CoreProcessSyntax p a x | p -&gt; a x where<br>&nbsp;&nbsp;&nbsp;&nbsp;zero :: p<br>&nbsp;&nbsp;&nbsp;&nbsp;sequence :: a -&gt; x -&gt; p
<br>&nbsp;&nbsp;&nbsp;&nbsp;compose :: [p] -&gt; p<br><br>class CoreAgentSyntax x p n | x -&gt; p n where<br>&nbsp;&nbsp;&nbsp;&nbsp;bind&nbsp;&nbsp;:: [n] -&gt; p -&gt; x<br>&nbsp;&nbsp;&nbsp;&nbsp;offer :: [n] -&gt; p -&gt; x<br><br>-- Freedom (as in freely generated)<br><br>data MinimalProcessSyntax l x =
<br>&nbsp;&nbsp;&nbsp;&nbsp; Null<br>&nbsp;&nbsp;&nbsp;&nbsp; | Sequence l x<br>&nbsp;&nbsp;&nbsp;&nbsp; | Composition [MinimalProcessSyntax l x]<br><br>data MinimalAgentSyntax n p =<br>&nbsp;&nbsp;&nbsp;&nbsp; Thunk (() -&gt; p)<br>&nbsp;&nbsp;&nbsp;&nbsp; | Abstraction ([n] -&gt; p)<br>&nbsp;&nbsp;&nbsp;&nbsp; | Concretion [n] p<br><br>-- Constraining freedom
<br><br>instance CoreProcessSyntax (MinimalProcessSyntax l x) l x where<br>&nbsp;&nbsp;&nbsp;&nbsp; zero = Null<br>&nbsp;&nbsp;&nbsp;&nbsp; sequence l a = Sequence l a<br>&nbsp;&nbsp;&nbsp;&nbsp; compose [] = zero<br>&nbsp;&nbsp;&nbsp;&nbsp; compose ps = Composition ps<br><br>instance CoreAgentSyntax (MinimalAgentSyntax n p) p n where
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bind [] proc = Thunk (\() -&gt; proc)<br><br>--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- TODO : lgm : need to substitute m for n in proc<br>--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bind (name:names) proc = Abstraction (\m -&gt; bind names proc)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- here&#39;s the possible implementation. I don&#39;t know if it&#39;s right.
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- But at least it types<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bind (name:names) proc = Abstraction (\m -&gt; comp $ bind names proc)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;where comp (Thunk f) = f ()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- comp (Concretion n p) = ...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;offer names proc = Concretion names proc
<br><br></blockquote></div><br><br clear="all"><br>-- <br>L.G. Meredith<br>Managing Partner<br>Biosimilarity LLC<br>505 N 72nd St<br>Seattle, WA 98103<br><br>+1 206.650.3740<br><br><a href="http://biosimilarity.blogspot.com">
http://biosimilarity.blogspot.com</a>