module Peano
abstract syntax
Nat = zero() | suc(n:Nat)
gom -p classical Peano.gom
module classical.Peano
abstract syntax
Nat = zero() | suc(n:Nat)
gom Peano.gom
2006-11-04 tonio
* src/tom/gom/parser/:
- add support for qualifier module names
the module "dir.mod" is similar to the declaration
of a module "mod" compiled with "--package dir" option
No Tom today, some minor bug prevents me to post my wonderful example It is the chance to play with other cool languages.
Since I left my old but well-working modem for the brand new livebox, i’m very unhappy. To illustrate this fact and to improve my ascii-art skills, figure 1 summarizes the story (yes, this a png, yes this is lame..but wordpress won’t let me insert spaces into code tags, nor verbatim ones).
One really annoying thing is the dhcp server that allocates a (apparently) random address to every new wireless connected computer. It means that I have to guess my brother’s ip address to establish an ssh/sftp connection. I thought I just had to do some broadcast ping on the network, but I didn’t find any command to do this.
/!\ Antoine, if you’re reading this : there surely is an os pre-built solution for this problem, please don’t make me feel like i am completely useless /!\
So i thought of ocaml as a scripting language. As a result i came out with a tiny script. Sorry again for the missing indentation. [edit: now working !]
open Thread
open Sys
let ping ip =
let ret = Sys.command ("ping -c1 "^ip^" > /dev/null") in
match ret with
0 -> print_string (ip^"tokn"); flush stdout
| _ -> ()
;;
let wait = List.iter Thread.join in
let t = ref [] in
let i = ref 1 in
while !i < 255 do
try
t := Thread.create ping ("192.168.1."^(string_of_int !i))::!t ;
i := !i+1
with
_ -> wait !t; t := []
done;
wait !t
;;
The only tricky part is the line _ -> wait !t; t := []
, which waits to the n first ping commands to end when the underlying os can’t create more processes anymore.Now let’s look at the profit of using caml here:
Why not boost some dying project like NetBSD by replacing sh with ocaml ? This surely would make a slashdot entry
PS: For real and funny ascii art, take a look at nerdboy.
One of my favourite way of wasting time is to take part to blind tests with my friends. This allow us to improve our knowledge of the great 80’s One problem with this game is that it requires a referee who can’t play, so no one wants to attend this role. That’s why, being good geeks, we decided to let the computer chose the tracks and decide who was right. To achieve this, my friend Paul (phd student in the led project) wrote a plugin for the great amarok music player, using the great python language. By the way, a python backend for tom is on the way … i’m just to lazy for the moment to handle indentation issues.
That’s cool, but the plugin was completly unsuable because of the accuracy of artists’ names required by the program. We then took a look at the existing algorithms which compute a sort of “sound equality”. The oldest and most famous of them seems to be the soundex one. The wikipedia description isn’t very precise but as you can see, it is mainly composed of rewrite rules :
The translation into Tom rules is straightforward. For instance, rule 4 is translated as follows:
public String removeDoubles(String s) {
%match (String s) {
(f,X*,x,x,Y*) -> { return removeDoubles(`f+`X*+`x+`Y*); }
(f,X*,x,'w',x,Y*) -> { return removeDoubles(`f+`X*+`x+`Y*); }
(f,X*,x,'h',x,Y*) -> { return removeDoubles(`f+`X*+`x+`Y*); }
}
return s;
}
I missed a character disjunction to express things like (f,X*,x,'h'|'z',x,Y*)
. I don’t know if it is possible with Tom, if not we’ll have to look at it. The code is therefore somewhat long but it is ok to read.
Now let’s play :
polux@betty:~$ java Soundex "bill evans" "byle evannz"
true
polux@betty:~$ java Soundex "bill evans" "britney spears"
false
I hope so ! However, as indicated by the wikipedia, the algorithm is far from perfect :
polux@betty:~$ java Soundex "franz schubert" "frank zappa"
true
At least, it splits artists into bad and good ones
cvs2svn --dump-only --keywords-off --no-default-eol ~/cvsroot
svn co svn+ssh://login@scm.gforge.inria.fr/svn/tom/jtom/trunk jtom
During the ρ-calculus workshop in London, Clement and I wrote a proofchecker for Lemuridae (available in Tom cvs), our proof assistant for superdeduction. What is this about ? In many logical formalisms, proofs are mathematical objects represented by a tree :
A proof assistant is a program that helps to interactively build such trees (even if the tree representation isn’t always obvious for the user). Thus, checking a proof basically means checking that a tree is well-formed.
The smart idea behind proof checkers is that even if your proof assistant has been written by the worst programmer ever and is over bugged, the proof is still validated by a little piece of code in which you can trust. In particular, this principle is the keystone of the commonly trusted coq proof assistant.
Here comes Tom ! The deduction rules (nodes of the tree) we have to check have the following shape :
where Γ and Δ stand for a list of formulae, and A and B represent formulae. Lists and patterns ? This looks like a job for tom. The rule above is simply checked by the following pattern :
rule("implies L",
(
rule(_,_,sequent((g1*,g2*),(A,d*)),_),
rule(_,_,sequent((g1*,B,g2*),d),_)
),
sequent((g1*,a,g2*),d),
a@implies(A,B)
)
This is practically like reading the deduction rule ! The only difference is the last argument of rule
which indicates the active formula. It is worth noticing the extensive use of non-linear and associative matching here. Given these patterns, our proof checker is 100 lines long and everybody can actually be conviced that it does what it is designed for. Compared to coq’s proof checker, which is 6568 lines long according to sloccount, and which looks like this :
(* since the head may be reducible, we might introduce lifts of 0 *)
let compact_stack head stk =
let rec strip_rec depth = function
| Zshift(k)::s -> strip_rec (depth+k) s
| Zupdate(m)::s ->
(* Be sure to create a new cell otherwise sharing would be
lost by the update operation *)
let h' = lft_fconstr depth head in
let _ = update m (h'.norm,h'.term) in
strip_rec depth s
| stk -> zshift depth stk in
strip_rec 0 stk
this is really a big step forward in proof assistants trusting. (ok, construction calculus is far more complicated than sequent calculus but still, caml code for sequent calculus would look the same).
One issue remains : how can we trust tom’s generated code ? Easy answer : it has been certified … using Coq.
Tom is a cool language which adds powerful (associative (on lists)) pattern matching and strategic programming to Java (as well as C and ocaml).
Tom was designed for you !
You can download it here, or install the eclipse plugin as explained here (compiler included) and start to practice the tutorial right now !