Personal notes
--------------
(partially in italian)

Soluzioni
- per eseguire un pacchetto:
    cd ..
    java <nomepacchetto>.<nomeclasse>
- redirezionare output in MS-DOS:
  program ... >out 2>&1

Problems with Eclipse
- How could I redirect output under Eclipse? I never found the solution
  to this simple problem

Stilistics conventions in Java:
- packages are in lower case
- classes are capitalized
- methods have first letter in lower case
- fields have first letter in lower case

About automata
--------------

Automata are used for patterns (both the original ones and the subpatterns
created from the normalization) and for variables.
For variables there are 2 uses:
- it's created the automaton of the input type for semantic checks
  (we need to intersect the input type with the patterns of the clauses
  for several checks). Note that we explicitly normalize the 
  declared type of the typeswitch variable before to create the 
  automaton, thus creating new patterns. It's not clear yet where to put
  new subpatterns and new subautomata (to expand patterns will give problems
  to the algorithms of other semantic checks?)
- when the exact types of the variables bound in clauses are computed
  we create an automaton for each variable.
Note that there are no collisions between these 2 uses, as the variable
in the typeswitch statement has not an inferred type.
Note also that this is a difference between the import(P) statement and the
x.recv(P) statement, as variables inside pattern in the recv statement
are checked against the type of the channel.

XML names
---------

XML tag names are case sensitives.
If I well remember they can start with a letter, a digit, a international
letter but not with a punctuation mark.
If I well remember they can't have spaces inside.
XML tag names can't start with # but they can start with _ or digit, for 
this reason now I call all special tags with #...

Detection of design errors
--------------------------
- detect error design: there is the need for label classes (~\{l1|..|ln} and
  String\{s1|..|sn})
- detect a problem with the difference algorithm: A = "a[_1] | b[_2]", 
  B = "a[_3]" -> A\B = "a[_1\_3] | b[_2]" but the algorithm computes
  "b[_2]": so the classical algorithm for string automata doesn't work 
  well.

Main current problem
--------------------

* guarda ab.xre, la visualizzazione delle variabili: la variabile 
  viene espansa prima del tempo (p.e. salta fuori _Empty): perch?
  HO RISOLTO STACCANDO LE VARIABILI DOPO AVER NORMALIZZATO (AVEVO BISOGNO
  DI VARIABILI NORMALIZZATE) MA QUESTO STRANO FENOMENO MI INQUIETA

* normalizzo prima di staccare le variabili.. non so quali siano le 
  conseguenze ma se non faccio cos devo creare nuovi sottopattern apposta
  per le variabili.
  PERCHE' STACCARE LE VARIABILI?
  Perch i tipi delle variabili non sono sempre sottoparti dell'albero
  originale della sintassi.
  P.e. se ho "P1 as x | P2 as x" il tipo di x  "P1 | P2" cos se io
  non duplico P1 e P2 le radici di questi sottopattern hanno 2 parent
  diversi, quello nel pattern originale e la barra verticale della 
  variabile

- hashing sui pattern: basta usare come chiave l'hashcode della stringa.
  Man mano che i pattern vengono normalizzati acquisiscono la chiave,
  cio la stringa con un piccolo accorgimento: le variabili devono essere
  accompagnate dallo scoping. Per esempio "String as x(0)"  diverso da
  "String as x(1)". Il numero tra parentesi che accompagna la variabile  
  lo SCOPING non il codice univoco (che sopravvive solo per scopi di 
  visualizzazione in fase di debug, per assicurarsi che l'algoritmo di 
  fusione funzioni bene e che non si utilizzi una variabile morta in seguito)

Note
----
- la post-scrittura di informazioni di debug non  molto comoda per il 
  debug: i problemi succedono prima e le informazioni non vengono visualizzate!
- conflitto tra l'automa usato per la variabile di typeswitch e i tipi
  calcolati? no
- controllare come viene a,b,(c,d),e (una virgola  inserita dentro
  l'altra? allora devo cambiare firstTag/nextTag)
  firstTag/nextTag usato solo su valori?
  su espressioni no?

Da aggiungere
-------------

Tutto ci che  da aggiungere serve per il typechecking.

- label classes
- not (^)

Motivare perch  necessario!

Algoritmi da implementare
-------------------------

Types:

Subtyping: S <: T iff v \in S -> v \in T for all v (EXP HARD)
Intersection: intersect(S,T) = U
Difference: S \ U = U

Patterns:

Exhaustiveness (T <: P1|..|Pn)
Irredundancy   (for all Pi intersect(Pi,T \ (P1 | .. | Pi-1)) <> \varnothing)
Non-ambiguity
Pattern type inference (NEW: QUADRATIC, OLD: EXP)

Altre cose da fare:
- tree hashing (Hosoya credo lo chiami hash consing)
  Attenzione con l'hashing perch 2 sottoalberi apparentemente identici
  possono essere diversi. Per esempio "(T1 as x),T2" pu essere diverso
  da se stesso quando la x si riferisce a 2 variabili diverse con lo stesso
  nome. Stesso ragionamento quando T1 e T2 sono pattern che contengono bindings

Ragionare sulle seguenti cose
-----------------------------

1 SIGNIFICATO LOCALE/GLOBALE DEI BINDINGS
Le variabili legate nella clausola import (cio nella recv) sono globali,
quelle legate nelle clausole del typeswitch sono locali.

2 FRAMMENTI XML / DOCUMENTI INTERI

3 RECV/SEND MONDADICA / POLIADICA

FINTI BUG
* controllo errori, scappa questo caso:
  P as X | ... X ...
  che  un errore perch X non  nello scope
  NO! non scappa perch qui X  una variabile (non un tipo) e questo 
  un linearity constraint broken (X  definito in una scelta ma non 
  nell'altra)
* TODO in Translate riga 462 e 470: quando cerco un tipo devo cercare solo 
  negli scope corretti (0 e il corrente) o dichiarare 
  "identificatore sconosciuto".
  Per questo dovrebbe esserci la funzione searchType 
  IL MOTIVO PER CUI NON E' UN BUG E' CHE QUANDO USO normalizePattern HO
  GIA' VERIFICATO CHE GLI IDENTIFICATORI SONO USATI IN MODO CORRETTO

Discorso sui visitors
---------------------

Visitors normalizzati ma forse pu ancora servire metterci le mani.
Ho tenuto WriteTokensVisitor perch  l'unico possibile Visitor che
riproduce la struttura originale dell'albero (se stacco pattern e 
variabili dall'albero prima di manipolare i pattern posso usare
WriteTokensVisitor anche dopo per riprodurre la struttura originale 
dell'albero)

Riepilogo dei Visitor attualmente esistenti:
... aggiornare ...

Doubts
------

- Int, Float question:
  - don't allow?
  - allow but without match as XDuce?
  - allow with matching (unlike XDuce)?
- string pattern matching? (XDuce doesn't have it but maybe it's not
  too much difficult to do)
- allow output of XML fragments?

Domande su XDuce
----------------

! "pat Y = p" fa parte del linguaggio?
    NO
! l[Int] o l[Float] fanno match? 
	NO
! l[String,a[String],String,b[String]] fa match? 
	SI
! espressioni aritmetiche ci sono in XDuce? 
	IN PARTE, con le funzioni esterne
   (iplus/rplus, iminus/rminus ecc..)
! E' possibile dichiarare un tipo con costanti? p.e.
	type Name = name[String],surname["Mazzara"]
    SI

? clausole non complete: warning a tempo di compilazione? e run-time?

Sul mistero di Int e Float (svelato):
Strano ma vero: #PCDATA corrisponde sempre a String e fa match sempre con 
string. Non si pu neppure salvare su XML un Int o un Float, solo il formato 
interno lo permette. L'unica cosa  usare le funzioni di conversione (p.e. 
int_of_string e string_of_int)