aboutsummaryrefslogtreecommitdiff
path: root/algebraic-structures.group.scm
blob: 5cac19f299d88ab8148c1b2c5cb4ce358c50dde3 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
(functor ((algebraic-structures group) (M (<> unit inv)))
    (<> unit inv pow)
  (import (only M <> unit inv)
          scheme
          (chicken base))

  (define (pow x n)
    (assert (exact-integer? n))
    (if (negative? n)
        (pow (inv x) (- n))
        (let loop ((i n)
                   (acc unit))
          (if (= i 0)
              acc
              (loop (sub1 i)
                    (<> acc x)))))))