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've done, but i'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> <<a href="mailto:oleg@pobox.com">oleg@pobox.com</a>
> 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>> The file compiles with ghc as is. If you uncomment the last
<br>> section, however, you see that to close the loop on the constraints for the<br>> agent syntax we hit a typing error. i <b><i>think</i></b> this is a hard<br>> constraint in Haskell that prevents this level of generality in the
<br>> specification, but maybe you can see a way around it.<br><br>I believe the Haskell typechecker is right<br><br>> instance (Eq n, Eq p) =><br>> CoreAgentSyntax (MinimalAgentSyntax n p) where<br>> bind [] proc = Thunk (\() -> proc)
<br>><br>> data MinimalAgentSyntax n p =<br>> Thunk (() -> p)<br>> | Abstraction ([n] -> p)<br>> | Concretion [n] p<br><br>The bind method has the signature<br><br> bind :: (CoreProcessSyntax p, CoreAgentSyntax x) => [n] -> (p a x) -> 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 'p' and 'x'. However, when we
<br>define the instance<br><br>> CoreAgentSyntax (MinimalAgentSyntax n p) where<br>> bind [] proc = Thunk (\() -> proc)<br><br>we see that process proc and the agent aren't totally independent: the
<br>result of bind has the type 'MinimalAgentSyntax n process' and thus is<br>dependent on the 'process == p a x'. 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'm<br>not sure that line is correct:<br><br>-- -- TODO : lgm : need to substitute m for n in proc<br>-- bind (name:names) proc = Abstraction (\m -> bind names proc)
<br><br>According to the type of Abstraction, 'bind names proc' should have<br>the type 'p', 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's in a name?<br><br>class Nominal n where<br> nominate :: i -> 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> locate :: (Eq s, Nominal n) => s -> (n i) -> a s (n i)<br> name :: (Eq s, Nominal n) => a s (n i) -> (n i)<br><br>data Location s n = Locate s n deriving Eq
<br><br>instance Locality Location where<br> locate s n = Locate s n<br> name (Locate s n) = n<br><br><br>-- Constraints<br><br>class CoreProcessSyntax p a x | p -> a x where<br> zero :: p<br> sequence :: a -> x -> p
<br> compose :: [p] -> p<br><br>class CoreAgentSyntax x p n | x -> p n where<br> bind :: [n] -> p -> x<br> offer :: [n] -> p -> x<br><br>-- Freedom (as in freely generated)<br><br>data MinimalProcessSyntax l x =
<br> Null<br> | Sequence l x<br> | Composition [MinimalProcessSyntax l x]<br><br>data MinimalAgentSyntax n p =<br> Thunk (() -> p)<br> | Abstraction ([n] -> p)<br> | Concretion [n] p<br><br>-- Constraining freedom
<br><br>instance CoreProcessSyntax (MinimalProcessSyntax l x) l x where<br> zero = Null<br> sequence l a = Sequence l a<br> compose [] = zero<br> compose ps = Composition ps<br><br>instance CoreAgentSyntax (MinimalAgentSyntax n p) p n where
<br> bind [] proc = Thunk (\() -> proc)<br><br>-- -- TODO : lgm : need to substitute m for n in proc<br>-- bind (name:names) proc = Abstraction (\m -> bind names proc)<br> -- here's the possible implementation. I don't know if it's right.
<br> -- But at least it types<br> bind (name:names) proc = Abstraction (\m -> comp $ bind names proc)<br> where comp (Thunk f) = f ()<br> -- comp (Concretion n p) = ...<br> 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>