X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Flablgtk%2Flablgtk_20000829-0.1.0%2Fexamples%2Fold%2Ffixpoint.ml;fp=helm%2FDEVEL%2Flablgtk%2Flablgtk_20000829-0.1.0%2Fexamples%2Fold%2Ffixpoint.ml;h=c41b11b50b6d9ec4813f7ff92919f1c19b283ac8;hb=2ee84a2a641938988703e329aef9fc3c5eb5aacf;hp=0000000000000000000000000000000000000000;hpb=34d83812af9b7064cc8f735c2a78169881140010;p=helm.git diff --git a/helm/DEVEL/lablgtk/lablgtk_20000829-0.1.0/examples/old/fixpoint.ml b/helm/DEVEL/lablgtk/lablgtk_20000829-0.1.0/examples/old/fixpoint.ml new file mode 100644 index 000000000..c41b11b50 --- /dev/null +++ b/helm/DEVEL/lablgtk/lablgtk_20000829-0.1.0/examples/old/fixpoint.ml @@ -0,0 +1,39 @@ +(* $Id$ *) + +open GtkData +open GtkBase +open GtkPack +open GtkWindow +open GtkEdit +open GtkMain + +let rec fix fun:f :eq x = + let x' = f x in + if eq x x' then x + else fix fun:f :eq x' + +let eq_float x y = abs_float (x -. y) < 1e-13 + +let _ = + let top = Window.create `TOPLEVEL in + GtkSignal.connect sig:Object.Signals.destroy top callback:Main.quit; + let hbox = Box.create `VERTICAL in + Container.add top hbox; + let entry = Entry.create () in + Entry.set entry max_length:20; + let tips = Tooltips.create () in + Tooltips.set_tip tips entry text:"Initial value for fix-point"; + let result = Entry.create () in + Entry.set result max_length:20 editable:false; + Box.pack hbox entry; + Box.pack hbox result; + + GtkSignal.connect sig:Editable.Signals.activate entry callback: + begin fun () -> + let x = try float_of_string (Entry.get_text entry) with _ -> 0.0 in + Entry.set entry text:(string_of_float (cos x)); + let res = fix fun:cos eq:eq_float x in + Entry.set result text:(string_of_float res) + end; + Widget.show_all top; + Main.main ()