<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -79,6 +79,24 @@ data Term
   | RegexTerm      String [String]
     deriving (Eq, Ord)
 
+-- Another design would be to split the Term type into
+-- SimpleTerm|CompositeTerm, and then do everything in one go, but
+-- that complicates syntax and semantics for end users. Let's do this
+-- one ugly thing instead, eh?
+a = AtomTerm
+compositeTerm NilTerm = ListTerm []
+compositeTerm (BoolTerm True) = TupleTerm [a &quot;bert&quot;, a &quot;true&quot;]
+compositeTerm (BoolTerm False) = TupleTerm [a &quot;bert&quot;, a &quot;false&quot;]
+compositeTerm (DictionaryTerm kvs) =
+  TupleTerm [a &quot;bert&quot;, a &quot;dict&quot;, 
+             ListTerm $ map (\(k, v) -&gt; TupleTerm [k, v]) kvs]
+compositeTerm (TimeTerm t) =
+  TupleTerm [a &quot;bert&quot;, a &quot;time&quot;, IntTerm mS, IntTerm s, IntTerm uS]
+  where
+    (mS, s, uS) = decomposeTime t
+compositeTerm (RegexTerm s os) = 
+  TupleTerm [a &quot;bert&quot;, a &quot;regex&quot;, ListTerm $ map a os]
+
 instance Show Term where
   -- Provide an erlang-compatible 'show' for terms. The results of
   -- this should be parseable as erlang source. 
@@ -104,22 +122,8 @@ showTerm (BinaryTerm b)
     wrap x = &quot;&lt;&lt;&quot; ++ x ++ &quot;&gt;&gt;&quot;
 showTerm (BigintTerm x) = show x
 showTerm (BigbigintTerm x) = show x
-showTerm NilTerm = &quot;[]&quot;
-showTerm (BoolTerm x) = 
-  printf &quot;{bert, %s}&quot; $ b x
-  where
-    b True  = &quot;true&quot;
-    b False = &quot;false&quot;
-showTerm (DictionaryTerm kvs) =
-  printf &quot;{bert, dict, [%s]}&quot; kvs'
-  where 
-    kvs' = intercalate &quot;, &quot;
-         $ map (\(k, v) -&gt; &quot;{&quot; ++ show k ++ &quot;,&quot; ++ show v ++ &quot;}&quot;) kvs
-showTerm (TimeTerm t) =
-  printf &quot;{bert, time, %s}&quot; $ intercalate &quot;, &quot; $ map show [mS, s, uS]
-  where (mS, s, uS) = decomposeTime t
-showTerm (RegexTerm s os) =
-  printf &quot;{bert, regex, \&quot;%s\&quot;, [%s]}&quot; s (intercalate &quot;, &quot; $ map (showTerm . AtomTerm) os)
+-- All other terms are composite:
+showTerm t = showTerm . compositeTerm $ t
 
 class BERT a where
   -- | Introduce a 'Term' from a Haskell value.
@@ -244,29 +248,11 @@ putTerm (ListTerm value)
   where 
     len = length value
     putNil = putWord8 106
-
 putTerm (BinaryTerm value) = tag 109 &gt;&gt; (put32i $ B.length value) &gt;&gt; putL value
 putTerm (BigintTerm value) = tag 110 &gt;&gt; putBigint put8i value
 putTerm (BigbigintTerm value) = tag 111 &gt;&gt; putBigint put32i value
--- Complex terms:
-putTerm NilTerm = putTerm $ TupleTerm [AtomTerm &quot;bert&quot;, AtomTerm &quot;nil&quot;]
-putTerm (BoolTerm value) =
-  putTerm $ TupleTerm [AtomTerm &quot;bert&quot;, AtomTerm value']
-  where
-    value' = if value then &quot;true&quot; else &quot;false&quot;
-putTerm (DictionaryTerm value) =
-  putTerm $ TupleTerm [
-             AtomTerm &quot;bert&quot;, AtomTerm &quot;dict&quot;, 
-             ListTerm $ map (\(k, v) -&gt; TupleTerm [k, v]) value]
-putTerm (TimeTerm t) =
-  putTerm $ TupleTerm [
-             AtomTerm &quot;bert&quot;, AtomTerm &quot;time&quot;, 
-             IntTerm mS, IntTerm s, IntTerm uS]
-  where (mS, s, uS) = decomposeTime t
-putTerm (RegexTerm s os) =
-  putTerm $ TupleTerm [
-             AtomTerm &quot;bert&quot;, AtomTerm &quot;regex&quot;,
-             BytelistTerm (C.pack s), ListTerm $ map AtomTerm os]
+-- All other terms are composite:
+putTerm t = (putTerm . compositeTerm) $ t
 
 -- | Binary decoding of a single term (without header)
 getTerm = do
@@ -286,6 +272,7 @@ getTerm = do
     111 -&gt; getBigint get32i &gt;&gt;= return . BigintTerm . fromIntegral
   where
     getN n = replicateM n getTerm
+    -- First try &amp; decode composite terms.
     tupleTerm [AtomTerm &quot;bert&quot;, AtomTerm &quot;true&quot;]  = return $ BoolTerm True
     tupleTerm [AtomTerm &quot;bert&quot;, AtomTerm &quot;false&quot;] = return $ BoolTerm False
     tupleTerm [AtomTerm &quot;bert&quot;, AtomTerm &quot;dict&quot;, ListTerm kvs] =
@@ -304,6 +291,7 @@ getTerm = do
         options []                = return []
         options ((AtomTerm o):os) = options os &gt;&gt;= return . (o:)
         options _                 = fail &quot;regex options must be atoms&quot;
+    -- All other tuples are just .. tuples
     tupleTerm xs = return $ TupleTerm xs
 
 putBigint putter value = do</diff>
      <filename>Data/BERT/Term.hs</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>8ca25f5aee7a5b24765efc7d3b646f854a20149c</id>
    </parent>
  </parents>
  <author>
    <name>marius a. eriksen</name>
    <email>marius@monkey.org</email>
  </author>
  <url>http://github.com/mariusaeriksen/bert/commit/dfb6ce5b60f7f95272f1bb16af743d3e99ed4bf7</url>
  <id>dfb6ce5b60f7f95272f1bb16af743d3e99ed4bf7</id>
  <committed-date>2009-11-01T18:53:15-08:00</committed-date>
  <authored-date>2009-11-01T18:53:15-08:00</authored-date>
  <message>refactor &amp; simplify handling of composite terms</message>
  <tree>d6f817503890b4e533dafb1800ba7ae0efe927f5</tree>
  <committer>
    <name>marius a. eriksen</name>
    <email>marius@monkey.org</email>
  </committer>
</commit>
