This program shows how to use layout combinators to improve the visual appearance of a Fudget program.
We have made the previous Factorial function example more self documenting by adding labels to the entry field and the output display. We have also changed the order of the two parts: the entry field is now above the display.
Here is the source code:
import Fudgets main = fudlogue (shellF "Fac" facF) facF = placerF (revP verticalP) ( ("x! =" `labLeftOfF` intDispF) >==< mapF fac >==< ("x =" `labLeftOfF` intInputF)) fac 0 = 1 fac n = n * fac (n-1)
labLeftOfF
to put labels to the left of the entry field and the display.
(In Haskell, back quotes can be used to turn any function into an infix
operator, as we have done with labLeftOfF
here)
placerF
can
be applied to a composition of fudgets to specify the relative
placement of the parts. (The layout system automatically picks
some placement if you don't specify it yourself.)
The first argument
to placerF
is a placer, in our case
revP verticalP
, where
verticalP
causes the parts to be stacked vertically with the leftmost fudget
in the composition at the top, and
revP
reverses the order of the parts.