Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Latest commit

 

History

History
28 lines (28 loc) · 1.01 KB

8.20.md

File metadata and controls

28 lines (28 loc) · 1.01 KB
module sum-prod-maker
  interface
    ((ints : [opaque t
              zero : t
              succ : (t -> t)
              pred : (t -> t)
              is-zero : (t -> bool)])
     => [plus : (from ints take t -> (from ints take t -> from ints take t))
         times : (from ints take t -> (from ints take t -> from ints take t))])
  body
    [type t = from ints take t
     plus = letrec t plus(a : t) =
                       proc(b : t)
                         if (from ints take is-zero b)
                         then a
                         else (plus (from ints take succ a) (from ints take pred b))
            in plus
     times = letrec t times(a : t) = proc(b : t)
               letrec t times-rec(c : t) =
                          proc(d : t)
                            if (from ints take is-zero d)
                               from ints take zero
                               else (times-rec ((plus c) a) (from ints take pred d))
               in ((times-rec a) b)
              in times
    ]