aboutsummaryrefslogtreecommitdiff
path: root/source/lux/control/enum.lux
blob: 34910c837a48c6cb977b3ff7bdd2141eaa61e91a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
##  Copyright (c) Eduardo Julian. All rights reserved.
##  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
##  If a copy of the MPL was not distributed with this file,
##  You can obtain one at http://mozilla.org/MPL/2.0/.

(;import lux
         (lux/control ord))

## [Signatures]
(defsig #export (Enum e)
  (: (Ord e) _ord)
  (: (-> e e) succ)
  (: (-> e e) pre))

## [Functions]
(def #export (range' <= succ from to)
  (All [a] (-> (-> a a Bool) (-> a a) a a (List a)))
  (if (<= from to)
    (#;Cons from (range' <= succ (succ from) to))
    #;Nil))

(def #export (range enum from to)
  (All [a] (-> (Enum a) a a (List a)))
  (using enum
    (range' <= succ from to)))