<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Nov 12, 2010, at 10:40 AM, <a href="mailto:roconnor@theorem.ca">roconnor@theorem.ca</a> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">[1]Actaully the realizer for serialize is *weaker* that this axioms. &nbsp;The realizer for serialize would be (Nat -&gt; Nat) -&gt; IO Nat instead of (Nat -&gt; Nat) -&gt; Nat, so should have less impact that the Church-Turing axiom.</span></blockquote></div><br><div>I don't see where IO comes in if you're dealing with pure functions. &nbsp;Serializing pure structures is really really easy and can be done entirely purely. &nbsp;The tricky part is finding a good encoding.&nbsp;&nbsp;As I said in my original message on this topic, you are embedding a compiler and interpreter into your runtime. &nbsp;That can be as easy as what is below, or as tricky as embedding GHC in your runtime, or anywhere in between.</div><div><br></div><div>But you simply cannot serialize IO actions without the GHC runtime. &nbsp;The GHC runtime sequences IO actions in ways that depend on the unserializable environment. &nbsp;(Imposed) Sequencing + Concrete representation = Serialization.</div><div><br></div><div><div><font class="Apple-style-span" face="Courier">class Serialize a where&nbsp;</font></div><div><font class="Apple-style-span" face="Courier"></font><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp;serialize&nbsp;</font><span class="Apple-tab-span" style="white-space: pre; "><font class="Apple-style-span" face="Courier">        </font></span><font class="Apple-style-span" face="Courier">:: a -&gt; ByteString&nbsp;</font></div><div><font class="Apple-style-span" face="Courier"></font><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp;unSerialize &nbsp; &nbsp; &nbsp; :: ByteString -&gt; Maybe a&nbsp;<span class="Apple-style-span" style="white-space: pre; ">&nbsp;</span></font><font class="Apple-style-span" face="Courier">-- Parsers can fail</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">instance (Serialize a) =&gt; Serialize [a] where ...</font></div><div><font class="Apple-style-span" face="Courier">instance (Serialize a, Serialize b) =&gt; Serialize (a, b) where ...</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">-- We can conclude that a and b must be enumerable from the requirement that</font></div><div><font class="Apple-style-span" face="Courier">-- f is recursively enumerable:</font></div><div><span class="Apple-style-span" style="font-family: Courier; ">instance (Serialize a, Enum a, Serialize b, Enum b) =&gt; Serialize (a -&gt; b) where</span></div><div><span class="Apple-tab-span" style="white-space: pre; "><font class="Apple-style-span" face="Courier">        </font></span><font class="Apple-style-span" face="Courier">serialize f = serialize $ ( zip &nbsp; &nbsp; &nbsp; &nbsp; [minBound..maxBound]&nbsp;</font></div><div><span class="Apple-tab-span" style="white-space: pre; "><font class="Apple-style-span" face="Courier">                                        </font></span><font class="Apple-style-span" face="Courier">(fmap f [minBound..maxBound]) )</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">-- A map instance might be better: &nbsp;we trade some serialization time for more</font></div><div><font class="Apple-style-span" face="Courier">-- deserialization time. &nbsp;</font></div><div><font class="Apple-style-span" face="Courier">instance (Serialize a, Serialize b) =&gt; Serialize (Map a b) where ...</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">instance (Enum a, Enum b, Serialize a, Serialize b) =&gt; Serialize (a -&gt; b) where</font></div><div><font class="Apple-style-span" face="Courier"><span class="Apple-tab-span" style="white-space: pre; ">        </span>serialize f = serialize . fromList $&nbsp;</font><span class="Apple-style-span" style="font-family: Courier; ">( zip &nbsp; &nbsp; &nbsp; &nbsp; [minBound..maxBound]&nbsp;</span></div><div><span class="Apple-tab-span" style="white-space: pre; "><font class="Apple-style-span" face="Courier">                                                   </font></span><font class="Apple-style-span" face="Courier">(fmap f [minBound..maxBound]) )</font></div><div><font class="Apple-style-span" face="Courier"><span class="Apple-tab-span" style="white-space: pre; ">        </span>deserialize map = \x -&gt; lookup x (bytestring_decode_map map)</font></div><div><font class="Apple-style-span" face="Courier"><span class="Apple-tab-span" style="white-space: pre; ">                        </span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where bytestring_decode_map = ...</font></div></div></body></html>