Lambda Discipline

Examples

Shapes

examples/shapes.lbd

-- A shape is one of several kinds, each with its own measurements.
type Shape =
    | Circle Float
    | Rect Float Float

pi : Float = 3.14

area : Shape -> Float = \shape. match shape
    | Circle r -> (mul pi (mul r r))
    | Rect w h -> (mul w h)

-- A cylinder is a circle raised to a height.
volumeOfCylinder : Float -> Float -> Float = \r. \h. (mul (area (Circle r)) h)

(println (concat "Areas: " (show (map area [(Circle 1.0), (Rect 2.0 3.0)]))))
(println (concat "Volume of cylinder is: " (show (volumeOfCylinder 5.0 10.0))))

Output

Areas: [3.14, 6.0]
Volume of cylinder is: 785.0

Run it yourself from the repository root: lbd run examples/shapes.lbd