[Haskell-cafe] Prototype of a syntax reference

Maurí­cio briqueabraque at yahoo.com
Mon Aug 25 07:23:07 EDT 2008


Hi,

I'm trying to make a syntax reference in the form
of source code. It's not ready, but if someone
shares the same ideas I could use some
help. (Should I put this on a wiki? Where?)

My “design principles” are:

• It should contain just pieces of uncommented
   code. The idea is not to use it as a fast
   tutorial, but as a reminder of how to write all
   kinds of things, and solve all questions of type
   “is this allowed?”;

• It should be small, and fit on a printed A4
   page;

• It should show the complete syntax of
   everything, not the most common. For instance,
   ‘case of’ should show the use of guards;

• It should be an example of valid code, not good
   one. The idea is to show what can be done, not
   what should :)

• It should use expanded code, not identation
   rules. Replacement of identation for code (like
   {} etc.) have simple rules, and the proper way
   to ident can be deduced from expanded
   code. Sometimes this is important if we are
   trying to solve syntax errors;

• It should use Unicode. It's nice to know which
   kind of Unicode characters can actually be
   used;

• It should use no predefined types or classes
   except Bool. I’ll write a Prelude code reference
   if this first attempt go right.

So I came up with the weird code below. It should
contain a lot more, and be more dense (more syntax
examples per lines of code), but it's already
usefull for a begginer like me. What do you think?

Best,
Maurício


module Ça (Exèmplo(Åwirù,Øwet'Л,Øwet'И),aҝҧү,Clááá) where {

   class Clááá ú where {
     (⊗) :: ú -> ú -> ú;
     τAmber :: ú -> ú;
     τAmber a = a ⊗ a;
   };

   data D١ = U1 | U2 | U3; data D٢ = Vú1 | Vú2 | JustVú;
   data D٤ = Opção | OutraOpção;
   data Exèmplo = Åwirù | Øwet'Л D٤  | Øwet'И D٢ Exèmplo;

   osmesmos :: D٤ -> D٤ -> Bool;
   osmesmos Opção Opção = True; osmesmos OutraOpção OutraOpção = True;
   osmesmos _ _ = False;

   aҝҧү = (Øwet'И Vú2 aҝҧү) ⊗ Åwirù;

   instance Clááá Exèmplo where {
     Åwirù ⊗ _ = Åwirù;
     a@(Øwet'Л b) ⊗ x = case x of {
       Åwirù -> a;
       y@(Øwet'Л o) | (osmesmos o Opção) -> a | otherwise -> Øwet'И Vú1 y;
       y@(Øwet'И _ _) -> y ⊗ a
     };
     a@(Øwet'И Vú1 _) ⊗ _ = a;
     a@(Øwet'И Vú2 x) ⊗ _ = x;
     a@(Øwet'И JustVú _) ⊗ y = y;
   }
}



More information about the Haskell-Cafe mailing list