The program shows a numeric entry field labelled x= and a number display labelled fac(x)=. Whenever the user enters a number in the entry field and presses Return the factorial of that number is computed and displayed in the number display.
Here is the source code:
module Main where import Fudgets main = fudlogue (shellF "FacTst" mainF) mainF = outFacF >==< inIntF inIntF = "x=" `labLeftOfF` (inputDoneSP>^^=<intF) outFacF = "fac(x)=" `labLeftOfF` intDispF >=^< fac fac 0 = 1 fac n = n * fac(n-1)
inIntF
and the display outFacF
.
These two fudgets are combined into one with the operator
>==<
,
which connects the output of inIntF
to the input of
outFacF
. (See figure in the manual page for
>==<
.)
intF
creates an entry field for integer values. (There is also
stringF
for string values.)
>^^=<
to attach the special purpose stream processor
inputDoneSP
to remove the other messages from the output stream of intF
.
labLeftOfF
is used to attach a label to a fudget.
intDispF
creates integer displays.
>=^<
allows a function to be attached as a preprocessor to a fudget. In this
example the function fac
is applied to the input messages
received by outFacF
before they are delivered to the
integer display created by intDispF
.